|
16 | 16 | @pubnub = Pubnub.new(@pn_configuration)
|
17 | 17 | end
|
18 | 18 |
|
| 19 | +Given('I have a keyset with access manager enabled - without secret key') do |
| 20 | + expect(ENV['PAM_SUB_KEY']).not_to be_nil |
| 21 | + expect(ENV['PAM_PUB_KEY']).not_to be_nil |
| 22 | + @pn_configuration['subscribe_key'] = ENV['PAM_SUB_KEY'] |
| 23 | + @pn_configuration['publish_key'] = ENV['PAM_PUB_KEY'] |
| 24 | + logger = Logger.new(STDOUT) |
| 25 | + logger.level = Logger::DEBUG |
| 26 | + @pn_configuration['logger'] = logger |
| 27 | + |
| 28 | + @pubnub = Pubnub.new(@pn_configuration) |
| 29 | +end |
| 30 | + |
19 | 31 | Given('the authorized UUID {string}') do |uuid|
|
20 | 32 | @grant_token_state[:authorized_uuid] = uuid
|
21 | 33 | end
|
|
48 | 60 | }
|
49 | 61 | end
|
50 | 62 |
|
| 63 | +Given('a valid token with permissions to publish with channel {string}') do |string| |
| 64 | + @grant_token_state[:token] = token_with_all |
| 65 | +end |
| 66 | + |
| 67 | +Given('a token') do |
| 68 | + @grant_token_state[:token] = token_with_all |
| 69 | +end |
| 70 | + |
| 71 | +Given('an expired token with permissions to publish with channel {string}') do |string| |
| 72 | + @grant_token_state[:token] = token_with_all |
| 73 | +end |
| 74 | + |
51 | 75 | And('grant pattern permission {permissionType}') do |permission_type|
|
52 | 76 | current_pattern = @grant_token_state[:current_pattern]
|
53 | 77 | @grant_token_state[:current_grant][current_pattern][:permission_type].push(permission_type)
|
54 | 78 | end
|
55 | 79 |
|
56 |
| - |
57 | 80 | When('I grant a token specifying those permissions') do
|
58 | 81 | res = call_grant_token(@pubnub, @grant_token_state)
|
59 | 82 | @grant_token_state[:parsed_token] = @pubnub.parse_token(res.result[:data]["token"])
|
60 | 83 | end
|
61 | 84 |
|
| 85 | +When('I publish a message using that auth token with channel {string}') do |channel| |
| 86 | + @pubnub.set_token(@grant_token_state[:token]) |
| 87 | + res = @pubnub.publish( |
| 88 | + message: "This is message", |
| 89 | + channel: channel, |
| 90 | + http_sync: true |
| 91 | + ) |
| 92 | + @global_state[:last_call_res] = res |
| 93 | +end |
| 94 | + |
| 95 | +When('I attempt to publish a message using that auth token with channel {string}') do |channel| |
| 96 | + @pubnub.set_token(@grant_token_state[:token]) |
| 97 | + res = @pubnub.publish( |
| 98 | + message: "This is message", |
| 99 | + channel: channel, |
| 100 | + http_sync: true |
| 101 | + ) |
| 102 | + @global_state[:last_call_res] = res |
| 103 | +end |
| 104 | + |
| 105 | +When('I revoke a token') do |
| 106 | + res = @pubnub.revoke_token( |
| 107 | + token: @grant_token_state[:token], |
| 108 | + http_sync: true |
| 109 | + ) |
| 110 | + @global_state[:last_call_res] = res |
| 111 | +end |
| 112 | + |
62 | 113 | Then('the token contains the authorized UUID {string}') do |expected_uuid|
|
63 | 114 | expect(@grant_token_state[:parsed_token]["uuid"]).to eq expected_uuid
|
64 | 115 | end
|
|
115 | 166 | end
|
116 | 167 |
|
117 | 168 | When('I attempt to grant a token specifying those permissions') do
|
118 |
| - @grant_token_state[:error_response] = call_grant_token(@pubnub, @grant_token_state) |
| 169 | + @global_state[:last_call_res] = call_grant_token(@pubnub, @grant_token_state) |
119 | 170 | end
|
120 | 171 |
|
121 | 172 | Then('an error is returned') do
|
122 |
| - expect(@grant_token_state[:error_response]).not_to eq nil |
| 173 | + envelope = @global_state[:last_call_res] |
| 174 | + expect(envelope).not_to eq nil |
| 175 | + expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true |
123 | 176 | end
|
124 | 177 |
|
125 | 178 | Then('the error status code is {int}') do |code|
|
126 |
| - expect(@grant_token_state[:error_response].status[:code]).to eq code |
| 179 | + expect(@global_state[:last_call_res].status[:code]).to eq code |
127 | 180 | end
|
128 | 181 |
|
129 | 182 | Then('the error message is {string}') do |error_message|
|
130 |
| - expect(parse_error_body(@grant_token_state[:error_response])["error"]["message"]).to eq error_message |
| 183 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["message"]).to eq error_message |
131 | 184 | end
|
132 | 185 |
|
133 | 186 | Then('the error source is {string}') do |error_source|
|
134 |
| - expect(parse_error_body(@grant_token_state[:error_response])["error"]["source"]).to eq error_source |
| 187 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["source"]).to eq error_source |
135 | 188 | end
|
136 | 189 |
|
137 | 190 | Then('the error detail message is {string}') do |details_message|
|
138 |
| - expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["message"]).to eq details_message |
| 191 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["message"]).to eq details_message |
139 | 192 | end
|
140 | 193 |
|
141 | 194 | Then('the error detail location is {string}') do |details_location|
|
142 |
| - expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["location"]).to eq details_location |
| 195 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["location"]).to eq details_location |
143 | 196 | end
|
144 | 197 |
|
145 | 198 | Then('the error detail location type is {string}') do |location_type|
|
146 |
| - expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["locationType"]).to eq location_type |
| 199 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["locationType"]).to eq location_type |
147 | 200 | end
|
148 | 201 |
|
149 | 202 | Given('I have a known token containing an authorized UUID') do
|
|
165 | 218 | Given('I have a known token containing UUID pattern Permissions') do
|
166 | 219 | @grant_token_state[:token] = token_with_all
|
167 | 220 | end
|
| 221 | + |
| 222 | +Given('the token string {string}') do |token| |
| 223 | + @grant_token_state[:token] = token |
| 224 | +end |
| 225 | + |
| 226 | +Then('the result is successful') do |
| 227 | + envelope = @global_state[:last_call_res] |
| 228 | + expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq false |
| 229 | + expect(envelope.status[:code]).to eq 200 |
| 230 | +end |
| 231 | + |
| 232 | +Then('an auth error is returned') do |
| 233 | + envelope = @global_state[:last_call_res] |
| 234 | + expect(envelope).not_to eq nil |
| 235 | + expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true |
| 236 | +end |
| 237 | + |
| 238 | +Then('the auth error message is {string}') do |error_message| |
| 239 | + expect(parse_error_body(@global_state[:last_call_res])["message"]).to eq error_message |
| 240 | +end |
| 241 | + |
| 242 | +Then('the error service is {string}') do |service| |
| 243 | + expect(parse_error_body(@global_state[:last_call_res])["service"]).to eq service |
| 244 | +end |
| 245 | + |
| 246 | +Then('I get confirmation that token has been revoked') do |
| 247 | + envelope = @global_state[:last_call_res] |
| 248 | + expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq false |
| 249 | + expect(envelope.status[:code]).to eq 200 |
| 250 | +end |
| 251 | + |
| 252 | +Then('the error detail message is not empty') do |
| 253 | + expect(parse_error_body(@global_state[:last_call_res])["error"]["message"].empty?).to eq false |
| 254 | +end |
| 255 | + |
| 256 | + |
0 commit comments