Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keycloak-mock

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycloak-mock - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

dist/error.d.ts

4

dist/database.d.ts

@@ -60,2 +60,6 @@ export declare type MockUserProfileAttributes = {

/**
* Finds an existing user by username.
*/
findUserByEmail(email: string): MockUser | null;
/**
* Attempts to match against a user with the specified

@@ -62,0 +66,0 @@ * username and password.

@@ -8,2 +8,3 @@ "use strict";

const isNil_1 = __importDefault(require("lodash/isNil"));
const error_1 = require("./error");
var MockUserCredentialType;

@@ -40,2 +41,9 @@ (function (MockUserCredentialType) {

/**
* Finds an existing user by username.
*/
findUserByEmail(email) {
const user = this.users.find((storedUser) => storedUser.profile.email === email);
return user || null;
}
/**
* Attempts to match against a user with the specified

@@ -86,7 +94,18 @@ * username and password.

const finalizedOptions = options || {};
const id = finalizedOptions.id || uuid_1.v4();
const email = finalizedOptions.email || "henk.jansen@gmail.com";
const username = finalizedOptions.username || email;
if (this.findUserByID(id)) {
throw new error_1.DuplicateUserError(`A user with id ${id} already exists`);
}
if (this.findUserByUsername(username)) {
throw new error_1.DuplicateUserError(`A user with username ${username} already exists`);
}
if (this.findUserByEmail(email)) {
throw new error_1.DuplicateUserError(`A user with email ${email} already exists`);
}
const profile = {
id: finalizedOptions.id || uuid_1.v4(),
id,
createdTimestamp: finalizedOptions.createdTimestamp || new Date().getTime(),
username: finalizedOptions.username || email,
username,
enabled: isNil_1.default(finalizedOptions.enabled)

@@ -93,0 +112,0 @@ ? true

@@ -5,1 +5,2 @@ export { Mock, MockOptions, activateMock, deactivateMock, getMock, getMockInstance, } from "./mock";

export { default as createBearerToken, CreateTokenOptions, } from "./createBearerToken";
export { DuplicateUserError } from "./error";

@@ -16,1 +16,3 @@ "use strict";

exports.createBearerToken = createBearerToken_1.default;
var error_1 = require("./error");
exports.DuplicateUserError = error_1.DuplicateUserError;

32

dist/views/createUser.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("../error");
const createUser = (instance, request, body) => {

@@ -12,13 +13,22 @@ const { user } = request;

}
const createdUser = instance.database.createUser({
username: body.username,
email: body.email,
enabled: body.enabled,
totp: body.totp,
emailVerified: body.emailVerified,
firstName: body.firstName,
lastName: body.lastName,
attributes: body.attributes,
credentials: body.credentials,
});
let createdUser = null;
try {
createdUser = instance.database.createUser({
username: body.username,
email: body.email,
enabled: body.enabled,
totp: body.totp,
emailVerified: body.emailVerified,
firstName: body.firstName,
lastName: body.lastName,
attributes: body.attributes,
credentials: body.credentials,
});
}
catch (error) {
if (error instanceof error_1.DuplicateUserError) {
return [409, { errorMessage: error.message }];
}
throw error;
}
const resourcePath = `/admin/realms/${instance.params.realm}/users/${createdUser.profile.id}`;

@@ -25,0 +35,0 @@ const resourceURL = instance.createURL(resourcePath);

import { v4 as uuidv4 } from "uuid";
import isNil from "lodash/isNil";
import { DuplicateUserError } from "./error";
export type MockUserProfileAttributes = {

@@ -84,2 +86,12 @@ [key: string]: [string];

/**
* Finds an existing user by username.
*/
findUserByEmail(email: string): MockUser | null {
const user = this.users.find(
(storedUser) => storedUser.profile.email === email
);
return user || null;
}
/**
* Attempts to match against a user with the specified

@@ -149,9 +161,27 @@ * username and password.

const id = finalizedOptions.id || uuidv4();
const email = finalizedOptions.email || "henk.jansen@gmail.com";
const username = finalizedOptions.username || email;
if (this.findUserByID(id)) {
throw new DuplicateUserError(`A user with id ${id} already exists`);
}
if (this.findUserByUsername(username)) {
throw new DuplicateUserError(
`A user with username ${username} already exists`
);
}
if (this.findUserByEmail(email)) {
throw new DuplicateUserError(
`A user with email ${email} already exists`
);
}
const profile: MockUserProfile = {
id: finalizedOptions.id || uuidv4(),
id,
createdTimestamp:
finalizedOptions.createdTimestamp || new Date().getTime(),
username: finalizedOptions.username || email,
username,
enabled: isNil(finalizedOptions.enabled)

@@ -158,0 +188,0 @@ ? true

@@ -26,1 +26,2 @@ export {

} from "./createBearerToken";
export { DuplicateUserError } from "./error";

@@ -6,2 +6,3 @@ import { v4 as uuidv4 } from "uuid";

import { MockUser, MockUserCredentialType } from "../database";
import { DuplicateUserError } from "../error";

@@ -19,14 +20,23 @@ const createUser: PostViewFn = (instance, request, body) => {

const createdUser = instance.database.createUser({
username: body.username,
email: body.email,
enabled: body.enabled,
totp: body.totp,
emailVerified: body.emailVerified,
firstName: body.firstName,
lastName: body.lastName,
attributes: body.attributes,
credentials: body.credentials,
});
let createdUser: MockUser | null = null;
try {
createdUser = instance.database.createUser({
username: body.username,
email: body.email,
enabled: body.enabled,
totp: body.totp,
emailVerified: body.emailVerified,
firstName: body.firstName,
lastName: body.lastName,
attributes: body.attributes,
credentials: body.credentials,
});
} catch (error) {
if (error instanceof DuplicateUserError) {
return [409, { errorMessage: error.message }];
}
throw error;
}
const resourcePath = `/admin/realms/${instance.params.realm}/users/${createdUser.profile.id}`;

@@ -33,0 +43,0 @@ const resourceURL = instance.createURL(resourcePath);

{
"name": "keycloak-mock",
"version": "1.0.6",
"version": "1.0.7",
"description": "Keycloak server mock for Node.js",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc