Skip to content

Commit b382302

Browse files
authored
Revoke token (#124)
Add revoke token
1 parent 05f9b7c commit b382302

File tree

14 files changed

+235
-29
lines changed

14 files changed

+235
-29
lines changed

.github/workflows/run_acceptance_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
sudo gem install bundler &&
2626
bundle install
2727
- name: Run acceptance tests (optional)
28-
run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_beta -p report_beta
28+
run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_beta -p report_beta -f pretty
2929
continue-on-error: true
3030
- name: Run acceptance tests (required)
31-
run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_main -p report_main
31+
run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_main -p report_main -f pretty
3232
- name: Combine test results
3333
if: always()
3434
run: |

.pubnub.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
version: "4.7.1"
2+
version: "4.8.0"
33
changelog:
4+
- date: 2021-12-16
5+
version: v4.8.0
6+
changes:
7+
- type: feature
8+
text: "Add revoke token feature."
49
- date: 2021-11-24
510
version: v4.7.1
611
changes:
@@ -403,6 +408,10 @@ features:
403408
access:
404409
- ACCESS-GRANT
405410
- ACCESS-SECRET-KEY-ALL-ACCESS
411+
- ACCESS-GRANT-TOKEN
412+
- ACCESS-PARSE-TOKEN
413+
- ACCESS-SET-TOKEN
414+
- ACCESS-REVOKE-TOKEN
406415
channel-groups:
407416
- CHANNEL-GROUPS-ADD-CHANNELS
408417
- CHANNEL-GROUPS-REMOVE-CHANNELS
@@ -612,7 +621,7 @@ sdks:
612621
- x86-64
613622
- distribution-type: package
614623
distribution-repository: RubyGems
615-
package-name: pubnub-4.7.1.gem
624+
package-name: pubnub-4.8.0.gem
616625
location: https://rubygems.org/gems/pubnub
617626
requires:
618627
- name: addressable
@@ -717,8 +726,8 @@ sdks:
717726
- x86-64
718727
- distribution-type: library
719728
distribution-repository: GitHub release
720-
package-name: pubnub-4.7.1.gem
721-
location: https://github.com/pubnub/ruby/releases/download/v4.7.1/pubnub-4.7.1.gem
729+
package-name: pubnub-4.8.0.gem
730+
location: https://github.com/pubnub/ruby/releases/download/v4.8.0/pubnub-4.8.0.gem
722731
requires:
723732
- name: addressable
724733
min-version: 2.0.0

CHANGELOG.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
## v4.7.1
2-
November 24 2021
3-
4-
#### Added
5-
- Add new method `all_history_messages` which return messages from requested interval or `since` / `before` date in single object.
6-
7-
#### Fixed
8-
- Fix exception raised when optional start / end not passed to `paged_history`.
9-
1+
## v4.8.0
2+
December 16 2021
3+
4+
#### Added
5+
- Add revoke token feature.
6+
7+
## v4.7.1
8+
November 24 2021
9+
10+
#### Added
11+
- Add new method `all_history_messages` which return messages from requested interval or `since` / `before` date in single object.
12+
13+
#### Fixed
14+
- Fix exception raised when optional start / end not passed to `paged_history`.
15+
1016
## v4.7.0
1117
November 09 2021
1218

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pubnub (4.7.1)
4+
pubnub (4.8.0)
55
addressable (>= 2.0.0)
66
concurrent-ruby (~> 1.1.5)
77
concurrent-ruby-edge (~> 0.5.0)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.7.1
1+
4.8.0

features/step_definitions/grant_token_steps.rb renamed to features/step_definitions/access_steps.rb

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
@pubnub = Pubnub.new(@pn_configuration)
1717
end
1818

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+
1931
Given('the authorized UUID {string}') do |uuid|
2032
@grant_token_state[:authorized_uuid] = uuid
2133
end
@@ -48,17 +60,56 @@
4860
}
4961
end
5062

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+
5175
And('grant pattern permission {permissionType}') do |permission_type|
5276
current_pattern = @grant_token_state[:current_pattern]
5377
@grant_token_state[:current_grant][current_pattern][:permission_type].push(permission_type)
5478
end
5579

56-
5780
When('I grant a token specifying those permissions') do
5881
res = call_grant_token(@pubnub, @grant_token_state)
5982
@grant_token_state[:parsed_token] = @pubnub.parse_token(res.result[:data]["token"])
6083
end
6184

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+
62113
Then('the token contains the authorized UUID {string}') do |expected_uuid|
63114
expect(@grant_token_state[:parsed_token]["uuid"]).to eq expected_uuid
64115
end
@@ -115,35 +166,37 @@
115166
end
116167

117168
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)
119170
end
120171

121172
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
123176
end
124177

125178
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
127180
end
128181

129182
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
131184
end
132185

133186
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
135188
end
136189

137190
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
139192
end
140193

141194
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
143196
end
144197

145198
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
147200
end
148201

149202
Given('I have a known token containing an authorized UUID') do
@@ -165,3 +218,39 @@
165218
Given('I have a known token containing UUID pattern Permissions') do
166219
@grant_token_state[:token] = token_with_all
167220
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+

features/support/hooks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Before do |scenario|
55
@grant_token_state = {}
6+
@global_state = {}
67
@grant_token_state[:current_grant] = {}
78
@pn_configuration = {}
89

lib/pubnub/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
require 'pubnub/validators/channel_registration'
3838
require 'pubnub/validators/grant'
3939
require 'pubnub/validators/grant_token'
40+
require 'pubnub/validators/revoke_token'
4041
require 'pubnub/validators/heartbeat'
4142
require 'pubnub/validators/here_now'
4243
require 'pubnub/validators/history'

lib/pubnub/client/events.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Pubnub
44
class Client
55
# Module that holds generator for all events
66
module Events
7-
EVENTS = %w[publish subscribe presence leave history here_now audit grant grant_token delete_messages
7+
EVENTS = %w[publish subscribe presence leave history here_now audit grant grant_token revoke_token delete_messages
88
revoke time heartbeat where_now set_state state channel_registration message_counts signal
99
add_channels_to_push list_push_provisions remove_channels_from_push remove_device_from_push
1010
set_uuid_metadata set_channel_metadata remove_uuid_metadata remove_channel_metadata

lib/pubnub/constants.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module Constants
5858
OPERATION_AUDIT = :audit
5959
OPERATION_GRANT = :grant
6060
OPERATION_GRANT_TOKEN = :grant_token
61+
OPERATION_REVOKE_TOKEN = :revoke_token
6162
OPERATION_REVOKE = :revoke
6263
OPERATION_DELETE = :delete
6364
OPERATION_LIST_ALL_CHANNEL_GROUPS = :list_all_channel_groups

0 commit comments

Comments
 (0)