Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@trigo/keycloak-api

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trigo/keycloak-api - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+15
lib/requests/add-realm-roles-to-user.js
'use strict';
const fetchAPI = require('../fetch-api');
module.exports = async ({realm, userId, roles, headers, ctx}) => {
const res = await fetchAPI({
method: 'post',
endpoint: `${ctx.config.authorizationEndpoint}`,
urlPart: `/admin/realms/${realm}/users/${userId}/role-mappings/realm`,
body: roles,
timeout: 60000,
headers,
});
return res;
};
'use strict';
const {expect} = require('chai');
const uuid = require('uuid');
const KeycloakApi = require('../keycloak-api');
const cfg = require('../../specs/test-config');
const specHelper = require('../../specs/helper');
describe(
__filename
.split('/')
.pop()
.split('.')[0],
() => {
let api, realmname, user, client, testRealmRole;
before(async () => {
const tokenProvider = specHelper.tokenProviderFactory();
realmname = `realm-${uuid()}`;
api = new KeycloakApi(cfg);
await api.waitForKeycloak();
await api.createRealm({
realm: {
realm: realmname,
enabled: true,
directGrantFlow: 'direct grant',
resetCredentialsFlow: 'reset credentials',
clientAuthenticationFlow: 'clients',
},
tokenProvider,
});
await api.createRealmRole({
realm: realmname,
role: {
name: 'test-realm-role',
},
tokenProvider,
});
const getRealmRolesRes = await api.getRealmRoles({
realm: realmname,
tokenProvider,
});
testRealmRole = getRealmRolesRes.data.find(
role => role.name === 'test-realm-role'
);
await api.createClient({
realm: realmname,
client: {
clientId: 'test-service-client',
secret: 'secret',
enabled: true,
clientAuthenticatorType: 'client-secret',
serviceAccountsEnabled: true,
},
tokenProvider,
});
const clients = await api.getClients({
realm: realmname,
query: {
clientId: 'test-service-client',
},
tokenProvider,
});
client = clients.data[0];
const userRes = await api.getServiceAccountUser({
realm: realmname,
clientId: client.id,
tokenProvider,
});
user = userRes.data;
});
after(async () => {
await api.deleteRealm({
realm: realmname,
tokenProvider: specHelper.tokenProviderFactory(),
});
});
it('adds the roles to the user', async () => {
const res = await api.addRealmRolesToUser({
realm: realmname,
userId: user.id,
roles: [testRealmRole],
tokenProvider: specHelper.tokenProviderFactory(),
});
expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined;
});
}
);
'use strict';
module.exports = ms => new Promise(resolve => setTimeout(resolve, ms));
MIT License
Copyright (c) 2023 TRIGO GmbH (https://trigodev.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+29
-17
{
"extends": ["trigo", "prettier"],
"extends": [
"trigo",
"prettier"
],
"plugins": [
"prettier"
],
"prettier"
],
"env": {
"node": true,
"mocha": true
},
},
"parserOptions": {
"sourceType": "script"
},
"sourceType": "script"
},
"rules": {
"strict": [2, "global"],
"strict": [
2,
"global"
],
"no-underscore-dangle": 0,
"prettier/prettier": ["error"]
"prettier/prettier": [
"warn"
]
},
"overrides": [{
"files": ["**/*.specs.js"],
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"prefer-destructuring": 0,
"no-unused-expressions": 0
"overrides": [
{
"files": [
"**/*.specs.js"
],
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"prefer-destructuring": 0,
"no-unused-expressions": 0
}
}
}]
}
]
}
+1
-1

@@ -1,1 +0,1 @@

v9.11.2
v18

@@ -8,2 +8,2 @@ {

"useTabs": true
}
}
version: '2'
services:
keycloak:
image: quay.io/keycloak/keycloak:12.0.4
image: quay.io/keycloak/keycloak:18.0.2-legacy
environment:

@@ -17,12 +17,12 @@ - KEYCLOAK_USER=admin

- 8080:8080
# depends_on:
# depends_on:
# - postgres
# postgres:
# image: postgres:10-alpine
# environment:
# postgres:
# image: postgres:10-alpine
# environment:
# - POSTGRES_PASSWORD=password
# - POSTGRES_USER=admin
# - POSTGRES_DB=keycloak
# ports:
# ports:
# - 5432:5432

@@ -9,3 +9,3 @@ version: '2'

image: ${UNIQUE_BUILD_IMAGE_NAME}
command: 'yarn run test'
command: 'npm run test'
environment:

@@ -18,3 +18,3 @@ - NODE_ENV=test

networks:
- 3s-sso_test
- keycloak_api_test
depends_on:

@@ -24,3 +24,3 @@ - keycloak

keycloak:
image: quay.io/keycloak/keycloak:12.0.4
image: quay.io/keycloak/keycloak:18.0.2-legacy
environment:

@@ -37,13 +37,13 @@ - KEYCLOAK_USER=admin

networks:
- 3s-sso_test
# depends_on:
- keycloak_api_test
# depends_on:
# - postgres
# postgres:
# image: postgres:10-alpine
# environment:
# postgres:
# image: postgres:10-alpine
# environment:
# - POSTGRES_PASSWORD=password
# - POSTGRES_USER=admin
# - POSTGRES_DB=keycloak
# networks:
# networks:
# - 3s-sso_test

@@ -56,6 +56,6 @@

networks:
- 3s-sso_test
- keycloak_api_test
networks:
3s-sso_test:
keycloak_api_test:
driver: bridge

@@ -1,1 +0,1 @@

FROM trigo/node-base:v15.5.1
FROM ghcr.io/trigo-at/node-base:20.0.0

@@ -5,2 +5,3 @@ 'use strict';

const fetch = require('node-fetch');
const FormData = require('form-data');

@@ -29,3 +30,7 @@ const {omit, path, mergeDeepRight, merge} = require('ramda');

}
const res = {data, statusCode: response.status, header: response.headers.raw()};
const res = {
data,
statusCode: response.status,
header: response.headers.raw(),
};
return res;

@@ -32,0 +37,0 @@ }

'use strict';
const jwt = require('jsonwebtoken');
const Boom = require('boom');
const Boom = require('@hapi/boom');
const debug = require('debug')('@trigo/keycloak-api:get-token');

@@ -6,0 +6,0 @@

@@ -41,2 +41,12 @@ 'use strict';

async addRealmRolesToUser({realm, userId, roles, tokenProvider}) {
return retryOn401({
fn: requests.addRealmRolesToUser,
options: {realm, userId, roles},
getHeaders,
tokenProvider,
ctx: this,
});
}
async setUserPassword({

@@ -43,0 +53,0 @@ realm,

@@ -68,8 +68,10 @@ 'use strict';

availableRoles = (await api.getAvailableClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
tokenProvider,
})).data;
availableRoles = (
await api.getAvailableClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
tokenProvider,
})
).data;
});

@@ -92,5 +94,5 @@ after(async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -35,9 +35,11 @@ 'use strict';

expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})
).statusCode
).to.equal(201);

@@ -63,6 +65,8 @@

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;
});

@@ -84,5 +88,5 @@ after(async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -67,5 +67,5 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -55,5 +55,5 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -44,5 +44,5 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -58,3 +58,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -75,3 +75,3 @@ let g1 = find(

expect(res2.statusCode).to.equal(201);
expect(res2.header).to.not.be.undefined
expect(res2.header).to.not.be.undefined;

@@ -82,3 +82,3 @@ const getRes = await api.getGroups({

});
expect(getRes.header).to.not.be.undefined
expect(getRes.header).to.not.be.undefined;

@@ -85,0 +85,0 @@ g1 = find(propEq('name', 'g1'), getRes.data);

@@ -46,5 +46,5 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -32,3 +32,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -35,0 +35,0 @@ after(async () => {

@@ -44,5 +44,5 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -37,3 +37,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -46,3 +46,3 @@

});
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
const grp = find(propEq('name', name), res.data);

@@ -69,3 +69,3 @@ expect(grp).to.exist;

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -78,5 +78,5 @@ const getRes = await api.getGroup({

expect(getRes.statusCode).to.equal(404);
expect(getRes.header).to.not.be.undefined
expect(getRes.header).to.not.be.undefined;
});
}
);

@@ -35,5 +35,5 @@ 'use strict';

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -49,6 +49,8 @@ 'use strict';

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;
});

@@ -69,3 +71,3 @@ after(async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -78,5 +80,5 @@ const getRes = await api.getUser({

expect(getRes.statusCode).to.equal(404);
expect(getRes.header).to.not.be.undefined
expect(getRes.header).to.not.be.undefined;
});
}
);

@@ -28,4 +28,4 @@ 'use strict';

host: 'smtp.mailtrap.io',
user: '03a5f83b9804b8',
password: '864d845780a69e',
user: 'c5a09047ff69ae',
password: '5d82393eb961ae',
port: 2525,

@@ -59,7 +59,9 @@ },

[user] = (await api.getUsers({
realm: realmname,
query: {username: 'u1'},
tokenProvider: specHelper.tokenProviderFactory(),
})).data;
[user] = (
await api.getUsers({
realm: realmname,
query: {username: 'u1'},
tokenProvider: specHelper.tokenProviderFactory(),
})
).data;
});

@@ -81,5 +83,5 @@ after(async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -254,10 +254,12 @@ 'use strict';

expect(response.data.length).to.gt(0);
expect(response.header).to.not.be.undefined
expect(response.header).to.not.be.undefined;
const withParsedRepresentations = response.data.map(adminEvent => ({
...adminEvent,
representation: adminEvent.representation
? JSON.parse(adminEvent.representation)
: undefined,
}));
const withParsedRepresentations = response.data.map(adminEvent => {
return {
...adminEvent,
representation: adminEvent.representation
? JSON.parse(adminEvent.representation)
: undefined,
};
});

@@ -264,0 +266,0 @@ const groupMembershipEvents = withParsedRepresentations.filter(

@@ -82,5 +82,5 @@ 'use strict';

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -53,5 +53,5 @@ 'use strict';

expect(res.data.length).to.gt(1);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -50,3 +50,3 @@ 'use strict';

expect(res.data.length).to.gt(1);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -66,5 +66,5 @@

expect(res.data[0].clientId).to.equal('test-client');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -145,3 +145,3 @@ 'use strict';

expect(response.data.length).to.gt(0);
expect(response.header).to.not.be.undefined
expect(response.header).to.not.be.undefined;

@@ -148,0 +148,0 @@ response.data.forEach(event => {

@@ -47,3 +47,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
res = await api.getGroups({

@@ -54,3 +54,3 @@ realm: realmname,

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -73,5 +73,5 @@

expect(g.data.name).to.eql('herbert');
expect(g.header).to.not.be.undefined
expect(g.header).to.not.be.undefined;
});
}
);

@@ -35,9 +35,11 @@ 'use strict';

expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})
).statusCode
).to.equal(201);

@@ -62,6 +64,8 @@ const grpsres = await api.getGroups({

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;

@@ -92,5 +96,5 @@ await api.addGroupToUser({

expect(res.data.length).to.equal(1);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -37,3 +37,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
res = await api.createGroup({

@@ -50,3 +50,3 @@ realm: realmname,

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
res = await api.getGroups({

@@ -57,3 +57,3 @@ realm: realmname,

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -78,5 +78,5 @@ group = find(propEq('name', 'franz'), res.data);

expect(g.data.attributes.test).to.eql(['prop']);
expect(g.header).to.not.be.undefined
expect(g.header).to.not.be.undefined;
});
}
);

@@ -35,9 +35,11 @@ 'use strict';

expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})
).statusCode
).to.equal(201);

@@ -62,6 +64,8 @@ const grpsres = await api.getGroups({

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;

@@ -91,5 +95,5 @@ await api.addGroupToUser({

expect(res.data[0].id).to.equal(group.id);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -37,3 +37,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
res = await api.createGroup({

@@ -47,3 +47,3 @@ realm: realmname,

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -65,3 +65,3 @@

expect(res.data.length).to.eql(2);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -68,0 +68,0 @@ expect(find(propEq('name', 'franz'), res.data)).to.exist;

'use strict';
const fetchAPI = require('../fetch-api.js');
const fetchAPI = require('../fetch-api');

@@ -5,0 +5,0 @@ module.exports = async ({realm, headers, ctx}) => {

@@ -41,6 +41,8 @@ 'use strict';

expect(res.statusCode).to.equal(200);
expect(res.data.keys.find(k => k.type === 'RSA').publicKey).to.be.a('string');
expect(res.header).to.not.be.undefined
expect(res.data.keys.find(k => k.type === 'RSA').publicKey).to.be.a(
'string'
);
expect(res.header).to.not.be.undefined;
});
}
);
'use strict';
const fetchAPI = require('../fetch-api.js');
const fetchAPI = require('../fetch-api');

@@ -5,0 +5,0 @@ module.exports = async ({realm, headers, ctx}) => {

@@ -43,5 +43,5 @@ 'use strict';

expect(res.data).to.be.an('array');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);
'use strict';
const fetchAPI = require('../fetch-api.js');
const fetchAPI = require('../fetch-api');

@@ -5,0 +5,0 @@ module.exports = async ({realm, headers, ctx}) => {

@@ -42,5 +42,5 @@ 'use strict';

expect(res.data.realm).to.equal(realmname);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);
'use strict';
const fetchAPI = require('../fetch-api.js');
const fetchAPI = require('../fetch-api');

@@ -5,0 +5,0 @@ module.exports = async ({headers, ctx}) => {

@@ -42,5 +42,5 @@ 'use strict';

expect(res.data).to.be.an('array');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -67,5 +67,5 @@ 'use strict';

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -60,5 +60,5 @@ 'use strict';

expect(res.data.access_token).to.be.a('string');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -56,6 +56,8 @@ 'use strict';

}
const users = (await api.getUsers({
realm: realmname,
tokenProvider: specHelper.tokenProviderFactory(),
})).data;
const users = (
await api.getUsers({
realm: realmname,
tokenProvider: specHelper.tokenProviderFactory(),
})
).data;
for (const user of users) {

@@ -89,5 +91,5 @@ await api.setUserPassword({

expect(res.data.refresh_token).to.be.a('string');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -56,6 +56,8 @@ 'use strict';

}
const users = (await api.getUsers({
realm: realmname,
tokenProvider: specHelper.tokenProviderFactory(),
})).data;
const users = (
await api.getUsers({
realm: realmname,
tokenProvider: specHelper.tokenProviderFactory(),
})
).data;
for (const user of users) {

@@ -87,3 +89,3 @@ await api.setUserPassword({

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
const at = res.data.access_token;

@@ -100,3 +102,3 @@ const rt = res.data.refresh_token;

expect(res.statusCode).to.equal(200);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
expect(res.data.access_token).to.be.a('string');

@@ -103,0 +105,0 @@ expect(res.data.access_token).to.not.equal(at);

@@ -49,6 +49,8 @@ 'use strict';

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;
});

@@ -70,5 +72,5 @@ after(async () => {

expect(res.data).to.be.an('object');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -64,3 +64,3 @@ 'use strict';

expect(res.data.length).to.eq(3);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -80,3 +80,3 @@

expect(res.data[0].username).to.equal('u2');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -96,3 +96,3 @@

expect(res.data[0].firstName).to.equal('fn2');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -111,3 +111,3 @@ it('query lastName', async () => {

expect(res.data[0].lastName).to.equal('ln2');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -126,3 +126,3 @@ it('query email', async () => {

expect(res.data[0].email).to.equal('u2@test.com');
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -133,3 +133,3 @@ it('query search', async () => {

query: {
search: '@test.com',
search: 'u2',
},

@@ -140,6 +140,6 @@ tokenProvider: specHelper.tokenProviderFactory(),

expect(res.data).to.be.an('array');
expect(res.data.length).to.equal(3);
expect(res.header).to.not.be.undefined
expect(res.data.length).to.equal(1);
expect(res.header).to.not.be.undefined;
});
}
);

@@ -34,18 +34,22 @@ 'use strict';

expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})
).statusCode
).to.equal(201);
expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g2',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g2',
},
tokenProvider,
})
).statusCode
).to.equal(201);

@@ -72,7 +76,9 @@

id: groups[1].id,
name: groups[1].name,
},
tokenProvider,
});
expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
const g = await api.getGroups({

@@ -83,5 +89,5 @@ realm: realmname,

expect(g.data[0].subGroups[0].id).to.equal(groups[1].id);
expect(g.header).to.not.be.undefined
expect(g.header).to.not.be.undefined;
});
}
);

@@ -75,17 +75,21 @@ 'use strict';

availableRoles = (await api.getAvailableClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
tokenProvider,
})).data;
expect(
(await api.addClientRolesToUser({
availableRoles = (
await api.getAvailableClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
roles: [availableRoles[0], availableRoles[1]],
tokenProvider,
})).statusCode
})
).data;
expect(
(
await api.addClientRolesToUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
roles: [availableRoles[0], availableRoles[1]],
tokenProvider,
})
).statusCode
).to.equal(204);

@@ -109,9 +113,11 @@ });

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
const urs = (await api.getClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
tokenProvider,
})).data;
expect(res.header).to.not.be.undefined;
const urs = (
await api.getClientRolesForUser({
realm: realmname,
userId: user.id,
clientId: rmClient.id,
tokenProvider,
})
).data;
expect(find(propEq('id', availableRoles[1].id), urs)).not.to.exist;

@@ -118,0 +124,0 @@ });

@@ -35,9 +35,11 @@ 'use strict';

expect(
(await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})).statusCode
(
await api.createGroup({
realm: realmname,
group: {
name: 'g1',
},
tokenProvider,
})
).statusCode
).to.equal(201);

@@ -63,6 +65,8 @@

}
users = (await api.getUsers({
realm: realmname,
tokenProvider,
})).data;
users = (
await api.getUsers({
realm: realmname,
tokenProvider,
})
).data;
await api.addGroupToUser({

@@ -91,5 +95,5 @@ realm: realmname,

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -49,7 +49,9 @@ 'use strict';

[user] = (await api.getUsers({
realm: realmname,
query: {username: 'u1'},
tokenProvider: specHelper.tokenProviderFactory(),
})).data;
[user] = (
await api.getUsers({
realm: realmname,
query: {username: 'u1'},
tokenProvider: specHelper.tokenProviderFactory(),
})
).data;
});

@@ -71,5 +73,5 @@ after(async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -72,5 +72,5 @@ 'use strict';

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});
}
);

@@ -37,3 +37,3 @@ 'use strict';

expect(res.statusCode).to.equal(201);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -46,3 +46,3 @@

});
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
const grp = find(propEq('name', name), res.data);

@@ -67,2 +67,3 @@ expect(grp).to.exist;

group: {
name: g.name,
id: g.id,

@@ -76,4 +77,5 @@ attributes: {

});
expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;

@@ -86,3 +88,3 @@ const ag = await api.getGroup({

expect(ag.data.attributes['at:trigo:test:prop1']).to.eql(['42']);
expect(ag.header).to.not.be.undefined
expect(ag.header).to.not.be.undefined;
const attr = ag.data.attributes['at:trigo:test:prop2'];

@@ -89,0 +91,0 @@ attr.sort();

@@ -71,3 +71,3 @@ 'use strict';

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
});

@@ -92,3 +92,3 @@ it('update user custom attributes', async () => {

expect(res.statusCode).to.equal(204);
expect(res.header).to.not.be.undefined
expect(res.header).to.not.be.undefined;
const ret = await api.getUser({

@@ -108,5 +108,5 @@ realm: realmname,

expect(ret.data.attributes).to.eql(exp);
expect(ret.header).to.not.be.undefined
expect(ret.header).to.not.be.undefined;
});
}
);
'use strict';
const {expect} = require('chai');
const bb = require('bluebird');
const waitForMs = require('./wait-for-ms');
const retryOn401 = require('./retry-on-401');

@@ -35,3 +36,3 @@ const getHeaders = require('./get-headers');

callCount++;
await bb.delay(10);
await waitForMs(10);
if (callCount < 2) {

@@ -38,0 +39,0 @@ return {

'use strict';
const bb = require('bluebird');
const waitForMs = require('./wait-for-ms');
const fetchAPI = require('./fetch-api');

@@ -17,7 +17,7 @@

ctx.log.info(e.message);
await bb.delay(500);
await waitForMs(500);
return tryAdminAuth();
}
if (res.statusCode !== 200) {
await bb.delay(500);
await waitForMs(500);
ctx.log.info('Wait for auth endpoint to become available...');

@@ -24,0 +24,0 @@ return tryAdminAuth();

{
"name": "@trigo/keycloak-api",
"version": "1.1.0",
"version": "1.2.0",
"description": "Node.js Keycloak Admin API Wrapper",

@@ -48,24 +48,23 @@ "main": "index.js",

"chai": "^4.1.2",
"eslint": "^5.6.0",
"eslint-config-prettier": "^3.1.0",
"eslint-config-trigo": "^6.0.1",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-trigo": "^4.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-prettier": "^2.6.2",
"husky": "^0.14.3",
"jsonwebtoken": "^8.3.0",
"lint-staged": "^7.3.0",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"prettier": "^1.14.3",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.2.0",
"jsonwebtoken": "^9.0.0",
"lint-staged": "^8.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^1.15.3",
"uuid": "^3.3.2"
},
"dependencies": {
"bluebird": "^3.5.2",
"boom": "^7.2.0",
"debug": "^4.1.0",
"form-data": "^2.3.2",
"node-fetch": "^2.2.0",
"@hapi/boom": "^10.0.1",
"debug": "^4.3.4",
"form-data": "^4.0.0",
"node-fetch": "^2.6.11",
"ramda": "^0.25.0"
}
}
}
'use strict';
const Boom = require('boom');
const Boom = require('@hapi/boom');
const cfg = require('../test-config');

@@ -5,0 +5,0 @@ const KeycloakApi = require('../../lib/keycloak-api');

Sorry, the diff of this file is not supported yet