scim-patch
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"022cf7b4-de7d-49d0-bad2-76eda8d7b6b5":{"parent":null,"children":[]}},"files":{"/home/travis/build/thomaspoignant/scim-patch/lib/src/scimPatch.js":["022cf7b4-de7d-49d0-bad2-76eda8d7b6b5"],"/home/travis/build/thomaspoignant/scim-patch/lib/src/errors/scimErrors.js":["022cf7b4-de7d-49d0-bad2-76eda8d7b6b5"]},"externalIds":{}} | ||
{"processes":{"12c40c98-9c96-4a86-b6e2-b17970438c44":{"parent":null,"children":[]}},"files":{"/home/travis/build/thomaspoignant/scim-patch/lib/src/scimPatch.js":["12c40c98-9c96-4a86-b6e2-b17970438c44"],"/home/travis/build/thomaspoignant/scim-patch/lib/src/errors/scimErrors.js":["12c40c98-9c96-4a86-b6e2-b17970438c44"]},"externalIds":{}} |
@@ -19,2 +19,3 @@ "use strict"; | ||
const ARRAY_SEARCH = /^(.+)\[(.+)\]$/; | ||
// Valid patch operation, value needs to be in lowercase here. | ||
const AUTHORIZED_OPERATION = ['remove', 'add', 'replace']; | ||
@@ -48,6 +49,9 @@ exports.PATCH_OPERATION_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:PatchOp'; | ||
case 'remove': | ||
case 'Remove': | ||
return applyRemoveOperation(patchedResource, patch); | ||
case 'add': | ||
case 'Add': | ||
return applyAddOperation(patchedResource, patch); | ||
case 'replace': | ||
case 'Replace': | ||
return applyReplaceOperation(patchedResource, patch); | ||
@@ -68,3 +72,3 @@ default: | ||
function validatePatchOperation(operation) { | ||
if (!operation.op || Array.isArray(operation.op) || !AUTHORIZED_OPERATION.includes(operation.op)) | ||
if (!operation.op || Array.isArray(operation.op) || !isValidOperation(operation.op)) | ||
throw new scimErrors_1.InvalidScimPatchRequest(`Invalid op "${operation.op}" in the request.`); | ||
@@ -242,2 +246,5 @@ if (operation.op === 'remove' && !operation.path) | ||
} | ||
function isValidOperation(operation) { | ||
return operation && AUTHORIZED_OPERATION.includes(operation.toLowerCase()); | ||
} | ||
class ScimSearchQuery { | ||
@@ -244,0 +251,0 @@ constructor(attrName, valuePath, array) { |
@@ -11,7 +11,7 @@ export declare type ScimPatchSchema = 'urn:ietf:params:scim:api:messages:2.0:PatchOp'; | ||
export interface ScimPatchRemoveOperation { | ||
readonly op: 'remove'; | ||
readonly op: 'remove' | 'Remove'; | ||
readonly path: string; | ||
} | ||
export interface ScimPatchAddReplaceOperation { | ||
readonly op: 'add' | 'replace'; | ||
readonly op: 'add' | 'Add' | 'replace' | 'Replace'; | ||
readonly path?: string; | ||
@@ -18,0 +18,0 @@ readonly value?: any; |
@@ -185,2 +185,9 @@ "use strict"; | ||
}); | ||
it('REPLACE: with capital first letter for operation', done => { | ||
const expected = false; | ||
const patch = { op: 'Replace', value: { active: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
}); | ||
}); | ||
@@ -357,2 +364,9 @@ describe('add', () => { | ||
}); | ||
it('ADD: with capital first letter for operation', done => { | ||
const expected = 'newValue'; | ||
const patch = { op: 'Add', value: { newProperty: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
}); | ||
@@ -412,2 +426,8 @@ describe('remove', () => { | ||
}); | ||
it('REMOVE: with capital first letter for operation', done => { | ||
const patch = { op: 'Remove', path: 'active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).not.to.exist; | ||
return done(); | ||
}); | ||
}); | ||
@@ -414,0 +434,0 @@ describe('invalid requests', () => { |
{ | ||
"name": "scim-patch", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "SCIM Patch operation (rfc7644).", | ||
@@ -29,3 +29,3 @@ "main": "lib/src/scimPatch.js", | ||
"coveralls": "^3.0.9", | ||
"mocha": "^6.2.2", | ||
"mocha": "^6.2.3", | ||
"nyc": "^15.0.0", | ||
@@ -32,0 +32,0 @@ "ts-node": "^8.5.0", |
@@ -5,3 +5,3 @@ # SCIM-PATCH | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fthomaspoignant%2Fscim-patch.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fthomaspoignant%2Fscim-patch?ref=badge_shield) | ||
[![Coverage Status](https://coveralls.io/repos/github/thomaspoignant/scim-patch/badge.svg?branch=master)](https://coveralls.io/github/thomaspoignant/scim-patch?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/thomaspoignant/scim-patch/badge.svg?branch=master&service=github)](https://coveralls.io/github/thomaspoignant/scim-patch?branch=master&service=github) | ||
@@ -8,0 +8,0 @@ [RFC7644 SCIM(System for Cross-domain Identity Management) 2.0](https://tools.ietf.org/html/rfc7644#section-3.5.2) implementation of the "Modifying with PATCH" section 3.5.2. |
@@ -49,5 +49,5 @@ import { | ||
const ARRAY_SEARCH: RegExp = /^(.+)\[(.+)\]$/; | ||
// Valid patch operation, value needs to be in lowercase here. | ||
const AUTHORIZED_OPERATION = ['remove', 'add', 'replace']; | ||
const AUTHORIZED_OPERATION = ['remove', 'add', 'replace'] as const; | ||
export const PATCH_OPERATION_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:PatchOp'; | ||
@@ -82,6 +82,9 @@ /* | ||
case 'remove': | ||
case 'Remove': | ||
return applyRemoveOperation(patchedResource, patch); | ||
case 'add': | ||
case 'Add': | ||
return applyAddOperation(patchedResource, patch); | ||
case 'replace': | ||
case 'Replace': | ||
return applyReplaceOperation(patchedResource, patch); | ||
@@ -102,3 +105,3 @@ default: | ||
function validatePatchOperation(operation: ScimPatchOperation): void { | ||
if (!operation.op || Array.isArray(operation.op) || !AUTHORIZED_OPERATION.includes(operation.op)) | ||
if (!operation.op || Array.isArray(operation.op) || !isValidOperation(operation.op)) | ||
throw new InvalidScimPatchRequest(`Invalid op "${operation.op}" in the request.`); | ||
@@ -318,2 +321,6 @@ | ||
function isValidOperation(operation: String): boolean { | ||
return operation && AUTHORIZED_OPERATION.includes(operation.toLowerCase()); | ||
} | ||
class ScimSearchQuery { | ||
@@ -320,0 +327,0 @@ constructor( |
@@ -16,3 +16,4 @@ export type ScimPatchSchema = 'urn:ietf:params:scim:api:messages:2.0:PatchOp'; | ||
export interface ScimPatchRemoveOperation { | ||
readonly op: 'remove'; | ||
// We accept value with capital letter to be compliant with AzureAD | ||
readonly op: 'remove' | 'Remove'; | ||
readonly path: string; | ||
@@ -22,3 +23,4 @@ } | ||
export interface ScimPatchAddReplaceOperation { | ||
readonly op: 'add' | 'replace'; | ||
// We accept value with capital letter to be compliant with AzureAD | ||
readonly op: 'add' | 'Add' | 'replace' | 'Replace'; | ||
readonly path?: string; | ||
@@ -25,0 +27,0 @@ readonly value?: any; |
@@ -205,2 +205,10 @@ import { | ||
}); | ||
it('REPLACE: with capital first letter for operation', done => { | ||
const expected = false; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'Replace', value: {active: expected}}; | ||
const afterPatch: ScimUser = <ScimUser>scimPatch(scimUser, [patch]); | ||
expect(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
}); | ||
}); | ||
@@ -390,2 +398,10 @@ | ||
}); | ||
it('ADD: with capital first letter for operation', done => { | ||
const expected = 'newValue'; | ||
const patch: ScimPatchAddReplaceOperation = {op: 'Add', value: {newProperty: expected}}; | ||
const afterPatch: ScimUser = <ScimUser>scimPatch(scimUser, [patch]); | ||
expect(afterPatch.newProperty).to.be.eq(expected); | ||
return done(); | ||
}); | ||
}); | ||
@@ -452,2 +468,9 @@ describe('remove', () => { | ||
}); | ||
it('REMOVE: with capital first letter for operation', done => { | ||
const patch: ScimPatchRemoveOperation = {op: 'Remove', path: 'active'}; | ||
const afterPatch: ScimUser = <ScimUser>scimPatch(scimUser, [patch]); | ||
expect(afterPatch.active).not.to.exist; | ||
return done(); | ||
}); | ||
}); | ||
@@ -454,0 +477,0 @@ describe('invalid requests', () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166850
1907