Skip to content

Commit 4b5d7f4

Browse files
authored
Add publisheronly token role (#272)
* Adding support for publisheronly role for client token creation
1 parent 5281d33 commit 4b5d7f4

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 4.9.0
2+
3+
* Adds the `publisheronly` role for client token creation. See [#272](https://github.com/opentok/OpenTok-Ruby-SDK/pull/272)
4+
15
# 4.8.1
26

37
* Fixes a bug with the `Archives#create` method. See [#269](https://github.com/opentok/OpenTok-Ruby-SDK/pull/269) and [#270](https://github.com/opentok/OpenTok-Ruby-SDK/pull/270)

lib/opentok/constants.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module OpenTok
22
require "set"
33
API_URL = "https://api.opentok.com"
44
TOKEN_SENTINEL = "T1=="
5-
ROLES = { subscriber: "subscriber", publisher: "publisher", moderator: "moderator" }
5+
ROLES = { subscriber: "subscriber", publisher: "publisher", moderator: "moderator", publisheronly: "publisheronly" }
66
ARCHIVE_MODES = ::Set.new([:manual, :always])
77
AUTH_EXPIRE = 300
88
end

lib/opentok/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module OpenTok
22
# @private
3-
VERSION = '4.8.1'
3+
VERSION = '4.9.0'
44
end

spec/shared/opentok_generates_tokens.rb

+39-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,29 @@
5050
expect(expiring_token).to carry_valid_token_signature api_secret
5151
end
5252

53-
it "generates tokens with a role" do
53+
it "generates tokens with a publisher role" do
54+
role = :publisher
55+
role_token = opentok.generate_token session_id, :role => role
56+
expect(role_token).to be_an_instance_of String
57+
expect(role_token).to carry_token_data :session_id => session_id
58+
expect(role_token).to carry_token_data :api_key => api_key
59+
expect(role_token).to carry_token_data :role => role
60+
expect(role_token).to carry_token_data [:nonce, :create_time]
61+
expect(role_token).to carry_valid_token_signature api_secret
62+
end
63+
64+
it "generates tokens with a subscriber role" do
65+
role = :subscriber
66+
role_token = opentok.generate_token session_id, :role => role
67+
expect(role_token).to be_an_instance_of String
68+
expect(role_token).to carry_token_data :session_id => session_id
69+
expect(role_token).to carry_token_data :api_key => api_key
70+
expect(role_token).to carry_token_data :role => role
71+
expect(role_token).to carry_token_data [:nonce, :create_time]
72+
expect(role_token).to carry_valid_token_signature api_secret
73+
end
74+
75+
it "generates tokens with a moderator role" do
5476
role = :moderator
5577
role_token = opentok.generate_token session_id, :role => role
5678
expect(role_token).to be_an_instance_of String
@@ -61,6 +83,17 @@
6183
expect(role_token).to carry_valid_token_signature api_secret
6284
end
6385

86+
it "generates tokens with a publisheronly role" do
87+
role = :publisheronly
88+
role_token = opentok.generate_token session_id, :role => role
89+
expect(role_token).to be_an_instance_of String
90+
expect(role_token).to carry_token_data :session_id => session_id
91+
expect(role_token).to carry_token_data :api_key => api_key
92+
expect(role_token).to carry_token_data :role => role
93+
expect(role_token).to carry_token_data [:nonce, :create_time]
94+
expect(role_token).to carry_valid_token_signature api_secret
95+
end
96+
6497
it "generates tokens with data" do
6598
data = "name=Johnny"
6699
data_bearing_token = opentok.generate_token session_id, :data => data
@@ -97,6 +130,11 @@
97130
expect(layout_class_bearing_token).to carry_valid_token_signature api_secret
98131
end
99132

133+
context "when the role is invalid" do
134+
it "raises an error" do
135+
expect { opentok.generate_token session_id, :role => :invalid_role }.to raise_error
136+
end
137+
end
100138

101139
# TODO a context about using a bad session_id
102140
end

0 commit comments

Comments
 (0)