diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 55650d8..890ded4 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -2,4 +2,3 @@ patreon: switcherapi ko_fi: petruki -custom: ['https://www.paypal.com/donate/?business=A5R6K3JAD8SW4&no_recurring=0&item_name=Thank+you+for+supporting+the+Open+Source+Community¤cy_code=CAD'] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7f2838e..b8411f7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -10,29 +10,8 @@ assignees: petruki **Describe the bug** A clear and concise description of what the bug is. -**To Reproduce from Switcher Management** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - **Expected behavior** A clear and concise description of what you expected to happen. -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - **Additional context** Add any other context about the problem here. diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 7f8fd51..93a30ad 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: Use Node.js 20.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20.x diff --git a/.github/workflows/re-release.yml b/.github/workflows/re-release.yml index 95bc35e..a55be2a 100644 --- a/.github/workflows/re-release.yml +++ b/.github/workflows/re-release.yml @@ -21,7 +21,7 @@ jobs: ref: ${{ github.event.inputs.tag }} - name: Use Node.js 20.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20.x diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2255e81..5b889b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - name: Use Node.js 20.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20.x diff --git a/package.json b/package.json index 52f61ce..e366b53 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.30.1", "mongodb": "^6.3.0", - "mongoose": "^8.1.3", + "mongoose": "^8.2.0", "pino": "^8.19.0", "pino-pretty": "^10.3.1", "swagger-ui-express": "^5.0.0", @@ -57,11 +57,11 @@ "babel-jest": "^29.7.0", "babel-polyfill": "^6.26.0", "env-cmd": "^10.1.0", - "eslint": "^8.56.0", + "eslint": "^8.57.0", "jest": "^29.7.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", - "nodemon": "^3.0.3", + "nodemon": "^3.1.0", "sinon": "^17.0.1", "supertest": "^6.3.4" }, diff --git a/src/models/component.js b/src/models/component.js index fcc58f3..3b87353 100644 --- a/src/models/component.js +++ b/src/models/component.js @@ -4,6 +4,10 @@ import { randomUUID } from 'crypto'; import jwt from 'jsonwebtoken'; import Domain from './domain'; +export const EncryptionSalts = Object.freeze({ + COMPONENT: 8 +}); + const componentSchema = new mongoose.Schema({ name: { type: String, @@ -40,7 +44,7 @@ componentSchema.methods.generateApiKey = async function () { const component = this; const apiKey = randomUUID(); - const hash = await bcryptjs.hash(apiKey, 8); + const hash = await bcryptjs.hash(apiKey, EncryptionSalts.COMPONENT); component.apihash = hash; await component.save(); diff --git a/src/routers/client-api.js b/src/routers/client-api.js index 95870e5..47af64f 100644 --- a/src/routers/client-api.js +++ b/src/routers/client-api.js @@ -68,7 +68,7 @@ router.post('/criteria/switchers_check', appAuth, clientLimiter, [ try { const configsFound = await getConfigs({ domain: req.domain, components: req.componentId }); const configs = configsFound.map(config => config.key); - res.send({ not_found: req.body.switchers.filter(switcher => !configs.includes(switcher)) }); + res.send({ not_found: req.body.switchers.filter(switcher => !configs.includes(String(switcher))) }); } catch (e) { res.status(500).send({ error: e.message }); } diff --git a/tests/fixtures/db_api.js b/tests/fixtures/db_api.js index 969b788..33fc126 100644 --- a/tests/fixtures/db_api.js +++ b/tests/fixtures/db_api.js @@ -6,7 +6,7 @@ import Admin from '../../src/models/admin'; import Domain from '../../src/models/domain'; import GroupConfig from '../../src/models/group-config'; import { Config } from '../../src/models/config'; -import Component from '../../src/models/component'; +import Component, { EncryptionSalts } from '../../src/models/component'; import { Metric } from '../../src/models/metric'; import { EnvType, Environment } from '../../src/models/environment'; import { ConfigStrategy, StrategiesType, OperationsType } from '../../src/models/config-strategy'; @@ -166,7 +166,7 @@ export const setupDatabase = async () => { await new Config(config2Document).save(); await new ConfigStrategy(configStrategyDocument).save(); - const hash = await bcryptjs.hash(component1Key, 8); + const hash = await bcryptjs.hash(component1Key, EncryptionSalts.COMPONENT); component1.apihash = hash; await new Component(component1).save(); }; \ No newline at end of file diff --git a/tests/fixtures/db_client.js b/tests/fixtures/db_client.js index 2c44462..7061627 100644 --- a/tests/fixtures/db_client.js +++ b/tests/fixtures/db_client.js @@ -6,7 +6,7 @@ import Admin from '../../src/models/admin'; import Domain from '../../src/models/domain'; import GroupConfig from '../../src/models/group-config'; import { Config } from '../../src/models/config'; -import Component from '../../src/models/component'; +import Component, { EncryptionSalts } from '../../src/models/component'; import { Metric } from '../../src/models/metric'; import { Environment, EnvType } from '../../src/models/environment'; import { ConfigStrategy, StrategiesType, OperationsType } from '../../src/models/config-strategy'; @@ -33,7 +33,7 @@ export const adminAccount = { active: true }; -export let apiKey; +export const apiKey = randomUUID(); export const domainId = new mongoose.Types.ObjectId(); export const domainDocument = { _id: domainId, @@ -185,9 +185,7 @@ export const setupDatabase = async () => { await new ConfigStrategy(configStrategyTIME_BETWEENDocument).save(); await new ConfigStrategy(configStrategyTIME_GREATDocument).save(); - const newApiKey = randomUUID(); - const hash = await bcryptjs.hash(newApiKey, 8); + const hash = await bcryptjs.hash(apiKey, EncryptionSalts.COMPONENT); component1.apihash = hash; await new Component(component1).save(); - apiKey = newApiKey; }; \ No newline at end of file diff --git a/tests/fixtures/db_client_payload.js b/tests/fixtures/db_client_payload.js index 711d485..56939bf 100644 --- a/tests/fixtures/db_client_payload.js +++ b/tests/fixtures/db_client_payload.js @@ -6,7 +6,7 @@ import Admin from '../../src/models/admin'; import Domain from '../../src/models/domain'; import GroupConfig from '../../src/models/group-config'; import { Config } from '../../src/models/config'; -import Component from '../../src/models/component'; +import Component, { EncryptionSalts } from '../../src/models/component'; import { Environment, EnvType } from '../../src/models/environment'; import { ConfigStrategy, StrategiesType, OperationsType } from '../../src/models/config-strategy'; @@ -32,7 +32,7 @@ export const adminAccount = { active: true }; -export let apiKey; +export const apiKey = randomUUID(); export const domainId = new mongoose.Types.ObjectId(); export const domainDocument = { _id: domainId, @@ -115,9 +115,7 @@ export const setupDatabase = async () => { await new Config(configPayloadDocument).save(); await new ConfigStrategy(configStrategyPAYLOAD_HAS_ONEDocument).save(); - const newApiKey = randomUUID(); - const hash = await bcryptjs.hash(newApiKey, 8); + const hash = await bcryptjs.hash(apiKey, EncryptionSalts.COMPONENT); component1.apihash = hash; await new Component(component1).save(); - apiKey = newApiKey; }; \ No newline at end of file diff --git a/tests/model/component.test.js b/tests/model/component.test.js index af333e9..6e8468d 100644 --- a/tests/model/component.test.js +++ b/tests/model/component.test.js @@ -9,7 +9,7 @@ import { domainId, domainDocument } from '../fixtures/db_api'; -import Component from '../../src/models/component'; +import Component, { EncryptionSalts } from '../../src/models/component'; afterAll(async () => { await new Promise(resolve => setTimeout(resolve, 1000)); @@ -25,13 +25,13 @@ describe('(Deprecated) Testing component authentication', () => { const generateApiKeyDeprecated = async (component) => { const buffer = randomBytes(32); const apiKey = Buffer.from(buffer).toString('base64'); - const hash = await bcryptjs.hash(apiKey, 8); + const hash = await bcryptjs.hash(apiKey, EncryptionSalts.COMPONENT); component.apihash = hash; await component.save(); const generatedApiKey = Buffer.from(apiKey).toString('base64'); return generatedApiKey; - } + }; test('COMPONENT_MODEL - Should authenticate component using old API key format', async () => { // Given