Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add publisheronly token role #272

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading