From f817d81c90b6b70b7e43e3536555322aebd09fc0 Mon Sep 17 00:00:00 2001 From: Cesare Rocchi Date: Mon, 11 Jun 2018 18:07:09 +0200 Subject: [PATCH] Add another JWT test with content-type application/jwt --- spec/realtime/auth.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/realtime/auth.test.js b/spec/realtime/auth.test.js index 96b5a43d25..9395164f0c 100644 --- a/spec/realtime/auth.test.js +++ b/spec/realtime/auth.test.js @@ -866,6 +866,37 @@ define(['ably', 'shared_helper', 'async'], function(Ably, helper, async) { }); }; + /* + * Request a token specifying a clientId and verify that the returned token + * has the requested clientId. Token will be returned with content-type application/jwt. + */ + exports.auth_jwt_with_clientid_application_jwt = function(test) { + test.expect(1); + var currentKey = helper.getTestApp().keys[0]; + var keys = {keyName: currentKey.keyName, keySecret: currentKey.keySecret, returnType: 'jwt'}; + var clientId = 'testJWTClientId'; + var params = mixin(keys, {clientId: clientId}); + var authCallback = function(tokenParams, callback) { + getJWT(params, callback); + }; + + var realtime = helper.AblyRealtime({ authCallback: authCallback }); + + realtime.connection.on('connected', function() { + test.equal(realtime.auth.clientId, clientId); + realtime.connection.close(); + test.done(); + return; + }); + + realtime.connection.on('failed', function(err) { + realtime.close(); + test.ok(false, "Failed: " + displayError(err)); + test.done(); + return; + }); + }; + /* * Request a token specifying subscribe-only capabilities and verify that posting * to a channel fails.