Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into API-1354
Browse files Browse the repository at this point in the history
  • Loading branch information
harunalpak committed Oct 24, 2022
2 parents fa5629a + 62a2183 commit 612882b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/discovery/HazelcastCloudDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class HazelcastCloudDiscovery {

let dataAsAString = '';
const req = get(endpointUrlOptions, (res: IncomingMessage) => {
if (res.statusCode != 200) {
deferred.reject(new HazelcastError('Your cluster discovery token is invalid.'));
return;
}
res.setEncoding('utf8');
res.on('data', (chunk) => {
dataAsAString += chunk;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/discovery/CloudDiscoveryInvalidTokenTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const { expect } = require('chai');
const {HazelcastCloudDiscovery} = require('../../../lib/discovery/HazelcastCloudDiscovery');
const { HazelcastError } = require('../../../lib');
const { ClientConfigImpl } = require('../../../lib/config/Config');
const {getRejectionReasonOrThrow} = require('../../TestUtil');

describe('Cloud Discovery Invalid Token Test', function () {
it('Cloud Discovery should throw proper error with an invalid token', async function () {
const clientConfig = new ClientConfigImpl();
const cloudDiscovery = new HazelcastCloudDiscovery(
clientConfig.properties['hazelcast.client.cloud.url'], 2 << 31
);

try {
const error = await getRejectionReasonOrThrow(cloudDiscovery.callService.bind(cloudDiscovery));
expect(error).to.be.instanceof(HazelcastError);
expect(error.message).to.include('discovery token is invalid');
} catch (err) {
console.log(err);
}
});
});

0 comments on commit 612882b

Please sign in to comment.