lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb in ably-rest-1.0.6 vs lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb in ably-rest-1.1.0

- old
+ new

@@ -756,13 +756,14 @@ auth.authorize(ttl: 26) expect(auth.token_params[:ttl]).to eql(26) end it 'updates the persisted auth options that are then used for subsequent authorize requests' do - expect(auth.options[:authUrl]).to be_nil - auth.authorize({}, authUrl: 'http://foo.com') - expect(auth.options[:authUrl]).to eql('http://foo.com') + auth_url = "https://echo.ably.io/?type=text&body=#{auth.request_token.token}" + expect(auth.options[:auth_url]).to be_nil + auth.authorize({}, auth_url: auth_url) + expect(auth.options[:auth_url]).to eql(auth_url) end context 'with a lambda for the :auth_callback option' do let(:client_id) { random_str } let!(:token) do @@ -1334,9 +1335,46 @@ end it 'returns a valid token (#RSA10l)' do response = client.auth.authorise expect(response).to be_a(Ably::Models::TokenDetails) + end + end + + # RSC1, RSC1a, RSA3c, RSA3d + context 'when using JWT' do + let(:auth_url) { 'https://echo.ably.io/createJWT' } + let(:token) { Faraday.get("#{auth_url}?keyName=#{key_name}&keySecret=#{key_secret}").body } + let(:client) { Ably::Rest::Client.new(token: token, environment: environment, protocol: protocol) } + + it 'authenticates correctly using the JWT token generated by the echo server' do + expect(client.stats).to_not be_nil() + end + + context 'when the JWT embeds an Ably token' do + let(:token) { Faraday.post(auth_url, { keyName: key_name, keySecret: key_secret, jwtType: :embedded }).body } + + it 'authenticates correctly using the embedded token' do + expect(client.stats).to_not be_nil() + end + + context 'and the requested token is encrypted' do + let(:token) { Faraday.post(auth_url, { keyName: key_name, keySecret: key_secret, jwtType: :embedded, encrypted: 1 }).body } + + it 'authenticates correctly using the embedded token' do + expect(client.stats).to_not be_nil() + end + end + end + + # RSA4f, RSA8c + context 'when the token requested is returned with application/jwt content type' do + let(:auth_rest_client) { Ably::Rest::Client.new(default_options.merge(key: api_key)) } + let(:auth_params) { { keyName: key_name, keySecret: key_secret, returnType: 'jwt' } } + let(:token) { auth_rest_client.auth.request_token({ }, { auth_url: auth_url, auth_params: auth_params }).token } + it 'authenticates correctly and pulls stats' do + expect(client.stats).to_not be_nil() + end end end end end