Skip to content

Commit c5fb632

Browse files
committed
Fixing lint issues | Adding dependency axios
1 parent f34da56 commit c5fb632

File tree

6 files changed

+69
-41
lines changed

6 files changed

+69
-41
lines changed

package-lock.json

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"ajv": "^6.12.6",
3636
"auth0": "^3.0.0",
37+
"axios": "^1.7.2",
3738
"dot-prop": "^5.2.0",
3839
"fs-extra": "^10.1.0",
3940
"global-agent": "^2.1.12",

src/tools/auth0/handlers/scimHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class ScimHandler {
7070

7171
// To avoid rate limiter error, we making API requests with a small delay.
7272
// TODO: However, this logic needs to be re-worked.
73-
await this.wait(200);
73+
await this.wait(500);
7474
} catch (err) {
7575
// Skip the connection if it returns 404. This can happen if `SCIM` is not enabled on a `SCIM` connection.
7676
if (err !== 'SCIM_NOT_FOUND') throw err;
@@ -96,7 +96,7 @@ export default class ScimHandler {
9696

9797
// To avoid rate limiter error, we making API requests with a small delay.
9898
// TODO: However, this logic needs to be re-worked.
99-
await this.wait(200);
99+
await this.wait(500);
100100
} catch (err) {
101101
// Skip the connection if it returns 404. This can happen if `SCIM` is not enabled on a `SCIM` connection.
102102
if (err !== 'SCIM_NOT_FOUND') throw err;

test/context/yaml/context.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import sinon from 'sinon';
66

77
import Context from '../../../src/context/yaml';
88
import { cleanThenMkdir, testDataDir, mockMgmtClient } from '../../utils';
9+
import ScimHandler from '../../../src/tools/auth0/handlers/scimHandler';
910

1011
describe('#YAML context validation', () => {
1112
it('should do nothing on empty yaml', async () => {
@@ -538,11 +539,8 @@ describe('#YAML context validation', () => {
538539
});
539540

540541
it('should preserve keywords when dumping', async () => {
541-
const scimHandlerMock = {
542-
applyScimConfiguration: (connections) => connections
543-
}
544-
const ScimHandler = require('../../../src/tools/auth0/handlers/scimHandler');
545-
sinon.stub(ScimHandler, 'default').returns(scimHandlerMock);
542+
const applyScimConfiguration = (connections) => connections;
543+
sinon.stub(ScimHandler.prototype, 'applyScimConfiguration').returns(applyScimConfiguration);
546544

547545
const dir = path.resolve(testDataDir, 'yaml', 'dump');
548546
cleanThenMkdir(dir);

test/tools/auth0/handlers/connections.tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable consistent-return */
22
const { expect } = require('chai');
3-
const connections = require('../../../../src/tools/auth0/handlers/connections');
43
const sinon = require('sinon');
4+
const connections = require('../../../../src/tools/auth0/handlers/connections');
55

66
const pool = {
77
addEachTask: (data) => {
@@ -67,11 +67,11 @@ describe('#connections handler', () => {
6767
connection_name: 'okta',
6868
strategy: 'okta',
6969
tenant_name: 'test-tenant',
70-
user_id_attribute: "externalId-1",
70+
user_id_attribute: 'externalId-1',
7171
mapping: [
7272
{
73-
scim: "scim_id",
74-
auth0: "auth0_id"
73+
scim: 'scim_id',
74+
auth0: 'auth0_id'
7575
}
7676
]
7777
}),

test/tools/auth0/handlers/scimHandler.tests.js

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ beforeEach(() => {
1515
};
1616

1717
scimHandler = new ScimHandler(
18-
function() { return "https://test-host.auth0.com" },
18+
function() { return 'https://test-host.auth0.com'; },
1919
{
2020
getAccessToken: async function () {
21-
return 'mock_access_token'
21+
return 'mock_access_token';
2222
}
2323
},
2424
connectionsManagerMock
@@ -29,11 +29,13 @@ describe('ScimHandler', () => {
2929
describe('#isScimStrategy', () => {
3030
it('should return true for SCIM strategy', () => {
3131
const response = scimHandler.isScimStrategy('samlp');
32+
// eslint-disable-next-line no-unused-expressions
3233
expect(response).to.be.true;
3334
});
3435

3536
it('should return false for non-SCIM strategy', () => {
3637
const response = scimHandler.isScimStrategy('oauth');
38+
// eslint-disable-next-line no-unused-expressions
3739
expect(response).to.be.false;
3840
});
3941
});
@@ -51,9 +53,13 @@ describe('ScimHandler', () => {
5153
getScimConfigurationStub.withArgs({ id: 'con_d3tmuoAkaUQgxN1f' }).rejects({ response: { data: { statusCode: 404 } } });
5254

5355
await scimHandler.createIdMap(connections);
54-
56+
// eslint-disable-next-line no-unused-expressions
5557
expect(scimHandler.idMap.get('con_KYp633cmKtnEQ31C')).to.deep.equal({ strategy: 'samlp', hasConfig: true });
58+
59+
// eslint-disable-next-line no-unused-expressions
5660
expect(scimHandler.idMap.get('con_Njd1bxE3QTqTRwAk')).to.be.undefined; // Because, it's a Non-SCIM connection.
61+
62+
// eslint-disable-next-line no-unused-expressions
5763
expect(scimHandler.idMap.get('con_d3tmuoAkaUQgxN1f')).to.be.undefined;
5864

5965
getScimConfigurationStub.restore();
@@ -74,8 +80,13 @@ describe('ScimHandler', () => {
7480

7581
await scimHandler.applyScimConfiguration(connections);
7682

83+
// eslint-disable-next-line no-unused-expressions
7784
expect(connections[0].scim_configuration).to.deep.equal({ user_id_attribute: 'externalId-1', mapping: [{ auth0: 'auth0_key', scim: 'scim_key' }] });
85+
86+
// eslint-disable-next-line no-unused-expressions
7887
expect(connections[1].scim_configuration).to.deep.equal({ user_id_attribute: 'externalId-2', mapping: [{ auth0: 'auth0_key', scim: 'scim_key' }] });
88+
89+
// eslint-disable-next-line no-unused-expressions
7990
expect(connections[2].scim_configuration).to.be.undefined;
8091

8192
getScimConfigurationStub.restore();
@@ -85,14 +96,16 @@ describe('ScimHandler', () => {
8596
describe('#scimHttpRequest', () => {
8697
it('should make HTTP request with correct authorization header', async () => {
8798
const accessToken = 'mock_access_token';
88-
const tokenProviderMock = {
89-
getAccessToken: sinon.stub().resolves(accessToken)
90-
};
9199
const axiosStub = sinon.stub(axios, 'get').resolves({ data: {} });
92100
const response = await scimHandler.scimHttpRequest('get', ['https://mock-domain/api/v2/connections/1/scim-configuration']);
93-
101+
102+
// eslint-disable-next-line no-unused-expressions
94103
expect(response).to.exist;
104+
105+
// eslint-disable-next-line no-unused-expressions
95106
expect(axiosStub.calledOnce).to.be.true;
107+
108+
// eslint-disable-next-line no-unused-expressions
96109
expect(axiosStub.firstCall.args[1].headers.Authorization).to.equal(`Bearer ${accessToken}`);
97110

98111
axiosStub.restore();
@@ -101,20 +114,20 @@ describe('ScimHandler', () => {
101114

102115
describe('#getScimConfiguration', () => {
103116
it('should return SCIM configuration for existing connection', async () => {
104-
const requestParams = { id: 'con_KYp633cmKtnEQ31C' }
117+
const requestParams = { id: 'con_KYp633cmKtnEQ31C' };
105118
const scimConfiguration = {
106119
connection_id: 'con_KYp633cmKtnEQ31C',
107120
connection_name: 'okta',
108121
strategy: 'okta',
109122
tenant_name: 'test-tenant',
110-
user_id_attribute: "externalId-1",
123+
user_id_attribute: 'externalId-1',
111124
mapping: [
112125
{
113-
scim: "scim_id",
114-
auth0: "auth0_id"
126+
scim: 'scim_id',
127+
auth0: 'auth0_id'
115128
}
116129
]
117-
}
130+
};
118131

119132
const axiosStub = sinon.stub(axios, 'get').resolves({ data: scimConfiguration, status: 201 });
120133
const response = await scimHandler.getScimConfiguration(requestParams);
@@ -160,7 +173,7 @@ describe('ScimHandler', () => {
160173
...payload,
161174
created_at: new Date().getTime(),
162175
updated_on: new Date().getTime()
163-
}
176+
};
164177

165178
it('should create new SCIM configuration', async () => {
166179
const axiosStub = sinon.stub(axios, 'post').resolves({ data: responseBody, status: 201 });
@@ -197,7 +210,7 @@ describe('ScimHandler', () => {
197210
...payload,
198211
created_at: new Date().getTime(),
199212
updated_on: new Date().getTime()
200-
}
213+
};
201214
const axiosStub = sinon.stub(axios, 'patch').resolves({ data: responseBody, status: 200 });
202215
const response = await scimHandler.updateScimConfiguration(requestParams, payload);
203216

@@ -214,15 +227,16 @@ describe('ScimHandler', () => {
214227
const requestParams = {
215228
id: 'con_PKp644cmKtnEB11J'
216229
};
217-
const axiosStub = sinon.stub(axios, 'delete').resolves({ status: 204 });
230+
const axiosStub = sinon.stub(axios, 'delete').resolves({ data: {}, status: 204 });
218231
const response = await scimHandler.deleteScimConfiguration(requestParams);
232+
expect(response).to.deep.equal({});
219233

220234
axiosStub.restore();
221235
});
222236
});
223237

224238
describe('#updateOverride', () => {
225-
it('should "update" connection and "update" SCIM configuration', async () => {
239+
it('should \'update\' connection and \'update\' SCIM configuration', async () => {
226240
const requestParams = { id: 'con_PKp644cmKtnEB11J' };
227241
const bodyParams = {
228242
id: 'con_PKp644cmKtnEB11J',
@@ -245,17 +259,19 @@ describe('ScimHandler', () => {
245259
idMapMock.set(requestParams.id, idMapEntry);
246260
scimHandler.idMap = idMapMock;
247261

248-
249262
const updateScimStub = sinon.stub(scimHandler, 'updateScimConfiguration').resolves({ data: {} });
250263
const response = await scimHandler.updateOverride(requestParams, bodyParams);
251264

265+
// eslint-disable-next-line no-unused-expressions
252266
expect(response).to.deep.equal(connectionUpdatePayload);
267+
268+
// eslint-disable-next-line no-unused-expressions
253269
expect(updateScimStub.calledOnceWith(requestParams, scimConfiguration)).to.be.true;
254270

255271
updateScimStub.restore();
256272
});
257273

258-
it('should "update" connection and "create" SCIM configuration', async () => {
274+
it('should \'update\' connection and \'create\' SCIM configuration', async () => {
259275
const requestParams = { id: 'con_PKp644cmKtnEB11J' };
260276
const bodyParams = {
261277
id: 'con_PKp644cmKtnEB11J',
@@ -281,13 +297,16 @@ describe('ScimHandler', () => {
281297
const createScimStub = sinon.stub(scimHandler, 'createScimConfiguration').resolves({ data: {} });
282298
const response = await scimHandler.updateOverride(requestParams, bodyParams);
283299

300+
// eslint-disable-next-line no-unused-expressions
284301
expect(response).to.deep.equal(connectionUpdatePayload);
302+
303+
// eslint-disable-next-line no-unused-expressions
285304
expect(createScimStub.calledOnceWith(requestParams, scimConfiguration)).to.be.true;
286305

287306
createScimStub.restore();
288307
});
289308

290-
it('should "update" connection and "delete" SCIM configuration', async () => {
309+
it('should \'update\' connection and \'delete\' SCIM configuration', async () => {
291310
const requestParams = { id: 'con_PKp644cmKtnEB11J' };
292311
const bodyParams = {
293312
id: 'con_PKp644cmKtnEB11J',
@@ -309,15 +328,18 @@ describe('ScimHandler', () => {
309328
const deleteScimStub = sinon.stub(scimHandler, 'deleteScimConfiguration').resolves({ data: {} });
310329
const response = await scimHandler.updateOverride(requestParams, bodyParams);
311330

331+
// eslint-disable-next-line no-unused-expressions
312332
expect(response).to.deep.equal(connectionUpdatePayload);
333+
334+
// eslint-disable-next-line no-unused-expressions
313335
expect(deleteScimStub.calledOnceWith(requestParams)).to.be.true;
314336

315337
deleteScimStub.restore();
316338
});
317339
});
318340

319341
describe('#createOverride', () => {
320-
it('should "create" connection and "create" SCIM configuration', async () => {
342+
it('should \'create\' connection and \'create\' SCIM configuration', async () => {
321343
const requestParams = { id: 'con_PKp644cmKtnEB11J' };
322344
const bodyParams = {
323345
id: 'con_PKp644cmKtnEB11J',
@@ -343,13 +365,16 @@ describe('ScimHandler', () => {
343365
const createScimStub = sinon.stub(scimHandler, 'createScimConfiguration').resolves({ data: {} });
344366
const response = await scimHandler.createOverride(bodyParams);
345367

368+
// eslint-disable-next-line no-unused-expressions
346369
expect(response).to.deep.equal(connectionCreatePayload);
370+
371+
// eslint-disable-next-line no-unused-expressions
347372
expect(createScimStub.calledOnceWith(requestParams, scimConfiguration)).to.be.true;
348373

349374
createScimStub.restore();
350375
});
351376

352-
it('should "create" connection without SCIM configuration', async () => {
377+
it('should \'create\' connection without SCIM configuration', async () => {
353378
const requestParams = { id: 'con_PKp644cmKtnEB11J' };
354379
const bodyParams = {
355380
id: 'con_PKp644cmKtnEB11J',
@@ -367,11 +392,13 @@ describe('ScimHandler', () => {
367392
idMapMock.set(requestParams.id, idMapEntry);
368393
scimHandler.idMap = idMapMock;
369394

370-
371395
const createScimStub = sinon.stub(scimHandler, 'createScimConfiguration').resolves({ data: {} });
372396
const response = await scimHandler.createOverride(requestParams, bodyParams);
373397

398+
// eslint-disable-next-line no-unused-expressions
374399
expect(response).to.deep.equal(connectionUpdatePayload);
400+
401+
// eslint-disable-next-line no-unused-expressions
375402
expect(createScimStub.calledOnce).to.be.false;
376403

377404
createScimStub.restore();

0 commit comments

Comments
 (0)