Skip to content

Commit

Permalink
Add publisheronly token role (#272)
Browse files Browse the repository at this point in the history
* Adding support for publisheronly role for client token creation
  • Loading branch information
superchilled authored Apr 22, 2024
1 parent 5281d33 commit 4b5d7f4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.9.0

* Adds the `publisheronly` role for client token creation. See [#272](https://github.com/opentok/OpenTok-Ruby-SDK/pull/272)

# 4.8.1

* 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)
Expand Down
2 changes: 1 addition & 1 deletion lib/opentok/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module OpenTok
require "set"
API_URL = "https://api.opentok.com"
TOKEN_SENTINEL = "T1=="
ROLES = { subscriber: "subscriber", publisher: "publisher", moderator: "moderator" }
ROLES = { subscriber: "subscriber", publisher: "publisher", moderator: "moderator", publisheronly: "publisheronly" }
ARCHIVE_MODES = ::Set.new([:manual, :always])
AUTH_EXPIRE = 300
end
2 changes: 1 addition & 1 deletion lib/opentok/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module OpenTok
# @private
VERSION = '4.8.1'
VERSION = '4.9.0'
end
40 changes: 39 additions & 1 deletion spec/shared/opentok_generates_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,29 @@
expect(expiring_token).to carry_valid_token_signature api_secret
end

it "generates tokens with a role" do
it "generates tokens with a publisher role" do
role = :publisher
role_token = opentok.generate_token session_id, :role => role
expect(role_token).to be_an_instance_of String
expect(role_token).to carry_token_data :session_id => session_id
expect(role_token).to carry_token_data :api_key => api_key
expect(role_token).to carry_token_data :role => role
expect(role_token).to carry_token_data [:nonce, :create_time]
expect(role_token).to carry_valid_token_signature api_secret
end

it "generates tokens with a subscriber role" do
role = :subscriber
role_token = opentok.generate_token session_id, :role => role
expect(role_token).to be_an_instance_of String
expect(role_token).to carry_token_data :session_id => session_id
expect(role_token).to carry_token_data :api_key => api_key
expect(role_token).to carry_token_data :role => role
expect(role_token).to carry_token_data [:nonce, :create_time]
expect(role_token).to carry_valid_token_signature api_secret
end

it "generates tokens with a moderator role" do
role = :moderator
role_token = opentok.generate_token session_id, :role => role
expect(role_token).to be_an_instance_of String
Expand All @@ -61,6 +83,17 @@
expect(role_token).to carry_valid_token_signature api_secret
end

it "generates tokens with a publisheronly role" do
role = :publisheronly
role_token = opentok.generate_token session_id, :role => role
expect(role_token).to be_an_instance_of String
expect(role_token).to carry_token_data :session_id => session_id
expect(role_token).to carry_token_data :api_key => api_key
expect(role_token).to carry_token_data :role => role
expect(role_token).to carry_token_data [:nonce, :create_time]
expect(role_token).to carry_valid_token_signature api_secret
end

it "generates tokens with data" do
data = "name=Johnny"
data_bearing_token = opentok.generate_token session_id, :data => data
Expand Down Expand Up @@ -97,6 +130,11 @@
expect(layout_class_bearing_token).to carry_valid_token_signature api_secret
end

context "when the role is invalid" do
it "raises an error" do
expect { opentok.generate_token session_id, :role => :invalid_role }.to raise_error
end
end

# TODO a context about using a bad session_id
end
Expand Down

0 comments on commit 4b5d7f4

Please sign in to comment.