264. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 8:04:41 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

264.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\tests\acceptance-tests\features\steps\helper HTTPartyRDK.rb Mon Aug 28 19:41:48 2017 UTC
2 rdk.zip\rdk\product\tests\acceptance-tests\features\steps\helper HTTPartyRDK.rb Tue Oct 3 20:07:23 2017 UTC

264.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 452
Changed 3 32
Inserted 0 0
Removed 0 0

264.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

264.4 Active regular expressions

No regular expressions were active.

264.5 Comparison detail

  1   require "h ttparty"
  2   require 'c ucumber/te rm/ansicol or'
  3  
  4   path = Fil e.expand_p ath '..',  __FILE__
  5   $LOAD_PATH .unshift p ath unless  $LOAD_PAT H.include? (path)
  6   require "D efaultLogi n.rb"
  7   require "T estSupport .rb"
  8   require "D omAccess.r b"
  9   require "P atientPick erDomEleme nts.rb"
  10  
  11   class Test Clients
  12     @users =  {}
  13  
  14       @users[" R E D A CTED "] = " REDACTED "
  15       @users[" REDA C TED "] = " REDACTED "
  16       @users[" R E D A CTED "] = " REDACTED "
  17       @users["Un authorized User"] = " PL        "
  18       @users["Au ditLogUser "] = " REDACTED "
  19       @users[" R E D A CTED ; REDACT "] = " REDACTED "
  20       @users[" R E D A CTED ;1tdnurse" ] = " DNS       "
  21       @users[" R E D A CTED ; DNS     "] = " REDACTED "
  22       @users[" R E D A CTED ; PL      "] = " REDACTED "
  23       @users[" REDA C TED ; PL      "] = " REDACTED "
  24       @users[" R E D A CTED ;nurse18"]  = " REDACTED "
  25       @users[' R E D A CTED ; DNS     '] = ' REDACTED
  26       @users[' REDA C
T ED;DNS      '] = ' REDAC T ED '
  27  
  28     def self .password_ for(userna me)
  29       return  @users[us ername]
  30     end
  31   end
  32  
  33   class Keyc hain < Has h
  34     def key( credential s)
  35       "#{cre dentials[: site]};#{c redentials [:accessCo de]};#{cre dentials[: verifyCode ]};#{crede ntials[:di vision]};"
  36     end
  37  
  38     def [](c redentials )
  39       super( key(creden tials))
  40     end
  41  
  42     def []=( credential s, value)
  43       super( key(creden tials), va lue)
  44     end
  45   end
  46  
  47   class HTTP artyRDK
  48     include  HTTParty
  49     @keychai n = Keycha in.new
  50     @time_st art = Time .new
  51     @time_do ne = Time. new
  52     @time_ou t_time = 3 00
  53     @divisio ns = {}
  54       @divisions [" R E D A CTED "] = "500"
  55       @divisions [" REDA C TED "] = "507"
  56  
  57     def self .default_c redentials
  58         return { : accessCode  => " REDACT ", :verify Code => " REDACTED ", :site = > " R E D A CTED ", :divisi on => "500 " }
  59     end
  60  
  61     def self .time_elap sed_last_c all
  62       return  @time_don e - @time_ start
  63     end
  64  
  65     def self .tokens_re ady(creden tials = de fault_cred entials)
  66       tokens  = @keycha in[credent ials]
  67       return  !tokens.n il? && (to kens[:expi res] - Tim e.now.utc  > 60)  # e xpires ove r 60 secon ds from no w
  68     end
  69  
  70     def self .build_opt ions(crede ntials)
  71       puts C olor.grey  "Using cre dentials:  #{credenti als}"
  72       tokens  = @keycha in[credent ials]
  73       header s = {}
  74       header s['Cookie' ] = tokens [:cookie]  unless tok ens[:cooki e].nil?
  75       header s['Authori zation'] =  tokens[:j wt] unless  tokens[:j wt].nil?
  76  
  77       option s = {}
  78       option s[:headers ] = header s
  79       option s[:verify]  = false
  80       option s[:timeout ] = @time_ out_time
  81       return  options
  82     end
  83  
  84     def self .acquire_t okens(cred entials =  {})
  85       payloa d = defaul t_credenti als.merge( credential s)
  86  
  87       authen tication_p ath = RDKQ uery.new(' authentica tion-authe ntication' ).path
  88       option s = { :bod y => paylo ad.to_json , :headers  => { 'Con tent-Type'  => 'appli cation/jso n' }, :tim eout => @t ime_out_ti me, :verif y => false  }
  89       puts C olor.grey  format_opt ions_to_cu rl('POST',  authentic ation_path , options)
  90       @respo nse = HTTP arty.post( authentica tion_path,  options)
  91       puts C olor.grey  "Authentic ation: #{p ayload} ha d a #{@res ponse.code } response "
  92  
  93       if @re sponse.cod e != 200
  94         @key chain[cred entials] =  nil
  95         retu rn @respon se
  96       end
  97  
  98       jwt =  @response. headers['X -Set-JWT']
  99       cookie  = @respon se.headers ['set-cook ie']
  100       puts C olor.grey  "Authentic ation JWT:  #{jwt.ins pect}"
  101       puts C olor.grey  "Authentic ation cook ie: #{cook ie.inspect }"
  102       cookie _hash = HT TParty::Co okieHash.n ew
  103       cookie _hash.add_ cookies(co okie)
  104       tokens  = {}
  105       tokens [:cookie]  = cookie_h ash.dup.to _cookie_st ring
  106       tokens [:expires]  = Time.pa rse(cookie _hash[:Exp ires]).utc
  107       tokens [:jwt] = " Bearer #{j wt}" unles s jwt.nil?
  108       @keych ain[creden tials] = t okens
  109       return  @response
  110     end
  111  
  112     def self .get_authe ntication_ options(cr edentials  = default_ credential s)
  113       @respo nse = nil
  114       option s = {}
  115       option s[:authent ication_re sponse] =  acquire_to kens(crede ntials) un less token s_ready(cr edentials)
  116       return  options
  117     end
  118  
  119     def self .get_crede ntials(use r, pass)
  120       creden tials = {}
  121       creden tials[:acc essCode] =  user.spli t(';')[1]
  122       creden tials[:sit e] = user. split(';') [0]
  123       creden tials[:ver ifyCode] =  pass
  124       creden tials[:div ision]= @d ivisions[u ser.split( ';')[0]]
  125       return  credentia ls
  126     end
  127  
  128     def self .add_body_ header_opt ions(optio ns, json,  headers)
  129       if jso n.is_a?(Ha sh)
  130         opti ons[:body]  = json.to _json
  131         head ers['Conte nt-Type']  = 'applica tion/json'  if header s['Content -Type'].ni l?
  132       else
  133         opti ons[:body]  = json un less json. nil?
  134       end
  135       option s[:headers ] = header s unless h eaders.emp ty?
  136     end
  137  
  138     def self .get(path,  json = ni l, headers  = {})
  139       option s = get_au thenticati on_options
  140       add_bo dy_header_ options(op tions, jso n, headers )
  141       return  wrap_http arty('get' , path, op tions)
  142     end
  143  
  144     def self .post(path , json = n il, header s = {})
  145       option s = get_au thenticati on_options
  146       add_bo dy_header_ options(op tions, jso n, headers )
  147       return  wrap_http arty('post ', path, o ptions)
  148     end
  149  
  150     def self .put(path,  json = ni l, headers  = {})
  151       option s = get_au thenticati on_options
  152       add_bo dy_header_ options(op tions, jso n, headers )
  153       return  wrap_http arty('put' , path, op tions)
  154     end
  155  
  156     def self .delete(pa th, json =  nil, head ers = {})
  157       option s = get_au thenticati on_options
  158       add_bo dy_header_ options(op tions, jso n, headers )
  159       return  wrap_http arty('dele te', path,  options)
  160     end
  161  
  162     def self .get_as_us er(path, u ser, pass,  json = ni l, headers  = {})
  163       creden tials = ge t_credenti als(user,  pass)
  164       option s = get_au thenticati on_options (credentia ls)
  165       add_bo dy_header_ options(op tions, jso n, headers )
  166       return  wrap_http arty('get' , path, op tions, cre dentials)
  167     end
  168  
  169     def self .post_as_u ser(path,  user, pass , json = n il, header s = {})
  170       creden tials = ge t_credenti als(user,  pass)
  171       option s = get_au thenticati on_options (credentia ls)
  172       add_bo dy_header_ options(op tions, jso n, headers )
  173       return  wrap_http arty('post ', path, o ptions, cr edentials)
  174     end
  175  
  176     def self .put_as_us er(path, u ser, pass,  json = ni l, headers  = {})
  177       creden tials = ge t_credenti als(user,  pass)
  178       option s = get_au thenticati on_options (credentia ls)
  179       add_bo dy_header_ options(op tions, jso n, headers )
  180       return  wrap_http arty('put' , path, op tions, cre dentials)
  181     end
  182  
  183     # Don't  call this  directly;  use the me thods abov e
  184     # We exp ect opt to  already c ontain aut henticated  tokens
  185     def self .wrap_http arty(metho d, path, o pt = {}, c redentials  = default _credentia ls)
  186       puts C olor.magen ta "#{meth od.upcase}  #{path}"
  187       @respo nse = nil
  188       return  opt[:auth entication _response]  if opt.ke y?(:authen tication_r esponse) & & opt[:aut henticatio n_response ].code !=  200
  189  
  190       option s = deep_m erge(build _options(c redentials ), opt)
  191       puts C olor.grey  format_opt ions_to_cu rl(method,  path, opt ions)
  192       begin
  193         @tim e_start =  Time.new
  194         begi n
  195           @r esponse =  HTTParty.s end(method .downcase,  path, opt ions)
  196           if  @response .code == 4 01
  197              puts Color .red "Fail ed credent ials: #{cr edentials} "
  198              puts Color .red "Fail ed keychai n: #{@keyc hain}"
  199              @keychain[ credential s] = nil
  200           en d
  201         resc ue Excepti on => e
  202           pu ts Color.r ed "Except ion: #{e}"
  203         end
  204         @tim e_done = T ime.new
  205         requ est_id = @ response.h eaders['X- Request-ID ']
  206         puts  Color.gre y "request Id: #{requ est_id}" i f request_ id
  207       rescue  Exception  => e
  208         @tim e_done = T ime.new
  209         puts  Color.red  "Time to  failure: # {time_elap sed_last_c all}"
  210         rais e e, "Time  to failur e: #{time_ elapsed_la st_call}"
  211       end
  212       if met hod.upcase  == 'DELET E' && path  == '/reso urce/authe ntication'
  213         @key chain[cred entials] =  nil
  214       end
  215       return  @response
  216     end
  217   end
  218  
  219   def format _options_t o_curl(met hod, path,  options)
  220     command  = ['curl - g -v']
  221     command  << "-X #{m ethod.upca se} " unle ss method. upcase ==  'GET'
  222     command  << options [:headers] .map { |k,  v| "-H '# {k}: #{v}' " }.join('  ')
  223     command  << "-d '#{ options[:b ody]}'" if  options[: body]
  224     command  << "'#{pat h}'"
  225     command. join(' ')
  226   end
  227  
  228   def deep_m erge(first , second)
  229     merger =  proc { |k ey, v1, v2 | (v1.is_a ? Hash) &&  (v2.is_a?  Hash) ? v 1.merge(v2 , &merger)  : v2 }
  230     first.me rge(second , &merger)
  231   end
  232  
  233   class Colo r
  234     extend C ucumber::T erm::ANSIC olor
  235     # clear  (reset)
  236     # bold,  dark
  237     # black,  red, gree n, yellow,  blue, mag enta, cyan , white
  238     def self .grey(stri ng)
  239       # Basi c ANSI gre y color, c ompatible  with Jenki ns
  240       bold(b lack(strin g))
  241     end
  242   end