From 39eb2e3fa7170b9ea2524ed140c782c75201c8c1 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:43:48 -0700 Subject: [PATCH] Fixes #538 - allow empty GitOps path --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- sonar-project.properties | 2 +- src/api-docs/swagger-info.js | 2 +- src/routers/gitops.js | 4 ++++ tests/gitops-account.test.js | 27 +++++++++++++++++++++++++++ 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 53d3ee5..6815d35 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "switcher-api", - "version": "1.3.0", + "version": "1.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "switcher-api", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "dependencies": { "axios": "^1.7.7", diff --git a/package.json b/package.json index ffa35eb..a19fc66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "switcher-api", - "version": "1.3.0", + "version": "1.3.1", "description": "Feature Flag/Toggle API", "main": "src/start.js", "type": "module", diff --git a/sonar-project.properties b/sonar-project.properties index 74ebb61..95a1b1e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=switcherapi_switcher-api sonar.projectName=switcher-api sonar.organization=switcherapi -sonar.projectVersion=1.3.0 +sonar.projectVersion=1.3.1 sonar.links.homepage=https://github.com/switcherapi/switcher-api sonar.testExecutionReportPaths=test-report.xml diff --git a/src/api-docs/swagger-info.js b/src/api-docs/swagger-info.js index 1c11670..ef8c371 100644 --- a/src/api-docs/swagger-info.js +++ b/src/api-docs/swagger-info.js @@ -1,6 +1,6 @@ export default { title: 'Switcher API', - version: 'v1.3.0', + version: 'v1.3.1', description: 'Switcher API is a Feature Flag API focused on toggling features over different environments and applications.', contact: { name: 'Roger Floriano (petruki)', diff --git a/src/routers/gitops.js b/src/routers/gitops.js index a970452..8e28cdd 100644 --- a/src/routers/gitops.js +++ b/src/routers/gitops.js @@ -34,6 +34,10 @@ const windowValidation = (value) => { }; const pathValidation = (value) => { + if (value.length === 0) { + return true; + } + if (value.startsWith('/') || value.endsWith('/') || value.includes('//')) { throw new Error('Invalid path value - cannot start or end with / or contain //'); } diff --git a/tests/gitops-account.test.js b/tests/gitops-account.test.js index acc73a8..a8b624d 100644 --- a/tests/gitops-account.test.js +++ b/tests/gitops-account.test.js @@ -157,6 +157,33 @@ describe('GitOps Account - Subscribe', () => { Client.forget('GITOPS_SUBSCRIPTION'); }); + + test('GITOPS_ACCOUNT_SUITE - Should subscribe account - with blank path', async () => { + // given + const requestPayload = JSON.parse(JSON.stringify(VALID_SUBSCRIPTION_REQUEST)); + requestPayload.path = ''; + + const expectedResponse = JSON.parse(JSON.stringify(requestPayload)); + expectedResponse.token = '...123'; + + const postStub = sinon.stub(axios, 'post').resolves({ + status: 201, + data: expectedResponse + }); + + // test + const req = await request(app) + .post('/gitops/v1/account/subscribe') + .set('Authorization', `Bearer ${adminAccountToken}`) + .send(requestPayload) + .expect(201); + + // assert + expect(req.body).toMatchObject(expectedResponse); + + postStub.restore(); + }); + test('GITOPS_ACCOUNT_SUITE - Should return error - error creating account', async () => { // given const postStub = sinon.stub(axios, 'post').resolves({