spec/acceptance/rest/auth_spec.rb in ably-1.0.6 vs spec/acceptance/rest/auth_spec.rb in ably-1.0.7

- old
+ new

@@ -1336,7 +1336,44 @@ 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