github.com/Venafi/vcert/v5@v5.10.2/aruba/features/step_definitions/my_steps.rb (about) 1 require 'date' 2 3 Then(/^it should show deprecated warning$/) do 4 steps %{ 5 Given the exit status should be 0 6 And the output should contain "Password authentication is deprecated" 7 } 8 end 9 10 Then(/^it should retrieve certificate$/) do 11 steps %{ 12 Given the exit status should be 0 13 And the output should contain "Successfully retrieved request for" 14 } 15 end 16 17 Then(/^it should post certificate request$/) do 18 steps %{ 19 Then the exit status should be 0 20 And the output should contain "Successfully posted request for" 21 } 22 end 23 24 Then(/^it should request certificate$/) do 25 steps %{ 26 Then the exit status should be 0 27 And the output should contain "Successfully requested certificate for" 28 } 29 end 30 31 Then(/^it should( not)? output( encrypted)? private key$/) do |negated, encrypted| 32 if encrypted 33 steps %{Then the output should#{negated} contain "-----BEGIN ENCRYPTED PRIVATE KEY-----"} 34 else 35 steps %{Then the output should#{negated} contain "-----BEGIN PRIVATE KEY-----"} 36 end 37 end 38 39 Then(/^it should( not)? output( encrypted)? RSA private key$/) do |negated, encrypted| 40 steps %{Then the output should#{negated} contain "-----BEGIN RSA PRIVATE KEY-----"} 41 if encrypted 42 steps %{Then the output should#{negated} contain "-----ENCRYPTED-----"} 43 end 44 end 45 46 And(/^it should( not)? output Pickup ID$/) do |negated| 47 steps %{Then the output should#{negated} match /^PickupID=".+"$/} 48 unless negated 49 m = last_command_started.output.match /^PickupID="(.+)"$/ 50 @pickup_id = m[1] 51 end 52 end 53 54 When(/^it should write Pickup ID to (?:a|the) file(?: named)? "([^"]*)"$/) do |filename| 55 steps %{Then the file named "#{filename}" should exist} 56 end 57 58 When(/^it should write( encrypted)? private key to (?:a|the) file(?: named)? "([^"]*)"$/) do |encrypted, filename| 59 steps %{Then the file named "#{filename}" should exist} 60 if encrypted 61 steps %{Then the file named "#{filename}" should contain "ENCRYPTED"} 62 end 63 end 64 65 And(/^show output$/) do 66 Kernel.puts last_command_started.output.to_s 67 end 68 69 And(/^it should( not)? output CSR$/) do |negated| 70 steps %{ 71 Then the exit status should be 0 72 And the output should#{negated} contain "-----BEGIN CERTIFICATE REQUEST-----" 73 } 74 end 75 76 And(/^it should( not)? write CSR to the file(?: named)? "(.+)"$/) do |negated, filename| 77 steps %{ 78 Then the exit status should be 0 79 And the file named "#{filename}" should#{negated} exist 80 } 81 end 82 83 And(/^it should( not)? write certificate to the file(?: named)? "(.+)"$/) do |negated, filename| 84 steps %{ 85 Then the exit status should be 0 86 And the file named "#{filename}" should#{negated} exist 87 } 88 end 89 90 And(/^I remember the output$/) do 91 last_command_started 92 @previous_command_output = last_command_started.output.to_s 93 end 94 95 When(/^the outputs should( not)? be the same$/) do |negated| 96 if negated 97 expect(last_command_started.output.to_s).not_to send(:an_output_string_being_eq, @previous_command_output) 98 else 99 expect(last_command_started.output.to_s).to send(:an_output_string_being_eq, @previous_command_output) 100 end 101 end 102 103 104 Then(/^it should( not)? output (access|refresh) token( in JSON)?$/) do |negated, token, json| 105 106 if @previous_command_output.nil? 107 fail(ArgumentError.new('@previous_command_output is nil')) 108 end 109 110 Kernel.puts("Checking output:\n"+@previous_command_output) 111 unless json 112 steps %{Then the output should#{negated} contain "access_token:"} 113 end 114 115 unless negated 116 if json then 117 # Since Ruby is returning both STDOUT and STDERR joined in string, in that order respectively. In order to find 118 # the expected JSON value, we will look for it, ignoring the rest of STDERR (if any). This started to happen when 119 # we introduced Zap Logging. The odd behavior is that this didn't happen before with regular standard logging 120 # from Golang, as during code examining we found out that, indeed, aruba is joining STDOUT and STDERR into one 121 # string, but we only need the STDOUT for parsing JSON. 122 123 json_string = extract_json_from_output(@previous_command_output) 124 125 JSON.parse(json_string) 126 if token === "access" 127 @access_token = unescape_text(normalize_json(json_string, "access_token")).tr('"', '') 128 elsif token === "refresh" 129 @refresh_token = unescape_text(normalize_json(json_string, "refresh_token")).tr('"', '') 130 else 131 fail(ArgumentError.new("Cant determine token type for #{token}")) 132 end 133 else 134 if token === "access" 135 m = @previous_command_output.match /access_token: (.+)$/ 136 @access_token = m[1] 137 elsif token === "refresh" 138 m = @previous_command_output.match /^refresh_token: (.+)$/ 139 @refresh_token = m[1] 140 else 141 fail(ArgumentError.new("Cant determine token type for #{token}")) 142 end 143 end 144 end 145 end 146 147 Then(/^it should( not)? output (application|expires|scope|refresh_until)( in JSON)?$/) do |negated, property, json| 148 149 if @previous_command_output.nil? 150 fail(ArgumentError.new('@previous_command_output is nil')) 151 end 152 153 Kernel.puts("Checking output:\n"+@previous_command_output) 154 unless json 155 steps %{Then the output should#{negated} contain "access_token_expires:"} 156 end 157 158 unless negated 159 if json then 160 json_string = extract_json_from_output(@previous_command_output) 161 JSON.parse(json_string) 162 if property === "application" 163 @application = unescape_text(normalize_json(json_string, "application")).tr('"', '') 164 elsif property === "expires" 165 @expires = unescape_text(normalize_json(json_string, "expires_ISO8601")).tr('"', '') 166 elsif property === "scope" 167 @scope = unescape_text(normalize_json(json_string, "scope")).tr('"', '') 168 elsif property === "refresh_until" 169 @refresh_until = unescape_text(normalize_json(json_string, "refresh_until")).tr('"', '') 170 Integer(@refresh_until) 171 else 172 fail(ArgumentError.new("Cant determine property type for #{property}")) 173 end 174 else 175 if property === "application" 176 m = @previous_command_output.match /^client_id: (.+)$/ 177 @application = m[1] 178 elsif property === "expires" 179 m = @previous_command_output.match /^access_token_expires: (.+)$/ 180 @expires = m[1] 181 elsif property === "scope" 182 m = @previous_command_output.match /^scope: (.+)$/ 183 @scope = m[1] 184 elsif property === "refresh_until" 185 m = @previous_command_output.match /^refresh_until: (.+)$/ 186 @refresh_until = m[1] 187 Date.parse(@refresh_until) 188 else 189 fail(ArgumentError.new("Cant determine property type for #{property}")) 190 end 191 end 192 end 193 end 194 195 Then(/^it should( not)? output revoked$/) do |negated| 196 Kernel.puts("Checking output:\n"+@previous_command_output) 197 steps %{Then the output should#{negated} contain "Access token grant successfully revoked"} 198 end