Skip to content

Commit

Permalink
test(secret-scan): Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvik9205 committed Nov 13, 2024
1 parent d880098 commit ca8bf76
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 258 deletions.
1 change: 1 addition & 0 deletions .github/workflows/validate-secret-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: secret-scan
files: /coverage/packages/secret-scan/coverage-final.json
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ flag_management:
target: 80%
- type: patch
target: 98%
- name: secret-scan
paths:
- packages/secret-scan/
carryforward: true
statuses:
- type: project
target: 80%
- type: patch
target: 98%
5 changes: 0 additions & 5 deletions packages/secret-scan/.mocharc.json

This file was deleted.

16 changes: 16 additions & 0 deletions packages/secret-scan/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
displayName: 'secret scan',
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'js', 'html'],
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
coverageDirectory: '../../coverage/packages/secret-scan',
coverageReporters: ['json'],
collectCoverage: true
}
6 changes: 2 additions & 4 deletions packages/secret-scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"genKey": "tsx src/generateKey.ts",
"build": "tsup",
"test": "mocha",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"test": "jest",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint \"{src,tests}/**/*.ts\" --fix"
},
"publishConfig": {
Expand All @@ -17,12 +17,10 @@
".": "./dist/index.js"
},
"dependencies": {
"mocha": "^10.6.0",
"randexp": "^0.5.3",
"tsx": "^4.16.2"
},
"devDependencies": {
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.10",
"eslint-config-standard-with-typescript": "^43.0.1",
"jest": "^29.5.0",
Expand Down
71 changes: 59 additions & 12 deletions packages/secret-scan/src/test/secret.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, it } from 'mocha'
import assert = require('assert')
import {
algolia,
alibaba,
Expand Down Expand Up @@ -71,16 +69,13 @@ import {
import type { TestCase } from '@/types'
import secretDetector from '@/index'

const testcaseTitleTemplate = (title: string) => `should detect ${title}`
const testcaseTitleTemplate = (title: string): string =>
`should detect ${title}`

function testSecret(testcase: TestCase[]) {
testcase.forEach(({ input, expected }, index) => {
function testSecret(testcases: TestCase[]): void {
testcases.forEach(({ input, expected }, index) => {
const result = secretDetector.detect(input)
assert.equal(
result.found,
expected,
`(i=${index}) For Input: ${input}, expected ${expected} but got ${result.found}`
)
expect(result.found).toBe(expected)
})
}

Expand Down Expand Up @@ -125,7 +120,6 @@ describe('Detect Secrets from string', () => {
testSecret(mailchimp.testcases)
})

// ! not working for seperated by dots, saying true to all
// it(testcaseTitleTemplate("JWT Key"), () => {
// testSecret(jwt.testcases);
// });
Expand All @@ -141,166 +135,219 @@ describe('Detect Secrets from string', () => {
it(testcaseTitleTemplate('Discord Token'), () => {
testSecret(discord.testcases)
})

it(testcaseTitleTemplate('Artifactory Token'), () => {
testSecret(artifactory.testcases)
})

it(testcaseTitleTemplate('AWS Token'), () => {
testSecret(aws.testcases)
})

it(testcaseTitleTemplate('Algolia Token'), () => {
testSecret(algolia.testcases)
})

it(testcaseTitleTemplate('Alibaba Key'), () => {
testSecret(alibaba.testcases)
})

it(testcaseTitleTemplate('Adafruit Key'), () => {
testSecret(adafruit.testcases)
})

it(testcaseTitleTemplate('Adobe Key'), () => {
testSecret(adobe.testcases)
})

it(testcaseTitleTemplate('Age Key'), () => {
testSecret(age.testcases)
})

it(testcaseTitleTemplate('Airtable Key'), () => {
testSecret(airtable.testcases)
})

it(testcaseTitleTemplate('Asana Key'), () => {
testSecret(asana.testcases)
})

it(testcaseTitleTemplate('Atlassian Key'), () => {
testSecret(atlassian.testcases)
})

it(testcaseTitleTemplate('Authress Key'), () => {
testSecret(authress.testcases)
})

it(testcaseTitleTemplate('Beamer Key'), () => {
testSecret(beamer.testcases)
})

it(testcaseTitleTemplate('Bitbucket Key'), () => {
testSecret(bitbucket.testcases)
})

it(testcaseTitleTemplate('Bittrex Key'), () => {
testSecret(bittrex.testcases)
})

it(testcaseTitleTemplate('Clojars Key'), () => {
testSecret(clojars.testcases)
})

it(testcaseTitleTemplate('Codecov Key'), () => {
testSecret(codecov.testcases)
})

it(testcaseTitleTemplate('Coinbase Key'), () => {
testSecret(coinbase.testcases)
})

it(testcaseTitleTemplate('Confluent Key'), () => {
testSecret(confluent.testcases)
})

it(testcaseTitleTemplate('Contentful Key'), () => {
testSecret(contentful.testcases)
})

it(testcaseTitleTemplate('Databricks Key'), () => {
testSecret(databricks.testcases)
})

it(testcaseTitleTemplate('Datadog Key'), () => {
testSecret(datadog.testcases)
})

it(testcaseTitleTemplate('Defined Networking Key'), () => {
testSecret(definednetworking.testcases)
})

it(testcaseTitleTemplate('Digital Ocean Key'), () => {
testSecret(digitalocean.testcases)
})

it(testcaseTitleTemplate('Doppler Key'), () => {
testSecret(doppler.testcases)
})

it(testcaseTitleTemplate('Dropbox Key'), () => {
testSecret(dropbox.testcases)
})

it(testcaseTitleTemplate('Duffel Key'), () => {
testSecret(duffel.testcases)
})

it(testcaseTitleTemplate('Dynatrace Key'), () => {
testSecret(dynatrace.testcases)
})

it(testcaseTitleTemplate('Easypost Key'), () => {
testSecret(easypost.testcases)
})

it(testcaseTitleTemplate('Facebook Key'), () => {
testSecret(facebook.testcases)
})

it(testcaseTitleTemplate('Flutterwave Key'), () => {
testSecret(flutterwave.testcases)
})

it(testcaseTitleTemplate('Frameio Key'), () => {
testSecret(frameio.testcases)
})

it(testcaseTitleTemplate('Gitlab Key'), () => {
testSecret(gitlab.testcases)
})

it(testcaseTitleTemplate('Grafana Key'), () => {
testSecret(grafana.testcases)
})

it(testcaseTitleTemplate('Harness Key'), () => {
testSecret(harness.testcases)
})

it(testcaseTitleTemplate('Hashicorp Key'), () => {
testSecret(hashicorp.testcases)
})

it(testcaseTitleTemplate('Heroku Key'), () => {
testSecret(heroku.testcases)
})

it(testcaseTitleTemplate('Hubspot Key'), () => {
testSecret(hubspot.testcases)
})

it(testcaseTitleTemplate('Huggingface Key'), () => {
testSecret(huggingface.testcases)
})

it(testcaseTitleTemplate('Infracost Key'), () => {
testSecret(infracost.testcases)
})

it(testcaseTitleTemplate('Intra42 Key'), () => {
testSecret(intra42.testcases)
})

// it(testcaseTitleTemplate('Kubernetes Key'), () => {
// testSecret(kubernetes.testcases)
// testSecret(kubernetes.testcases);
// });

it(testcaseTitleTemplate('Linear Key'), () => {
testSecret(linear.testcases)
})

it(testcaseTitleTemplate('Lob Key'), () => {
testSecret(lob.testcases)
})

it(testcaseTitleTemplate('Planetscale Key'), () => {
testSecret(planetscale.testcases)
})

it(testcaseTitleTemplate('Postman Key'), () => {
testSecret(postman.testcases)
})

it(testcaseTitleTemplate('Prefect Key'), () => {
testSecret(prefect.testcases)
})

it(testcaseTitleTemplate('Pulumi Key'), () => {
testSecret(pulumi.testcases)
})

it(testcaseTitleTemplate('Readme Key'), () => {
testSecret(readme.testcases)
})

it(testcaseTitleTemplate('Rubygems Key'), () => {
testSecret(rubygems.testcases)
})

it(testcaseTitleTemplate('Scalingo Key'), () => {
testSecret(scalingo.testcases)
})

it(testcaseTitleTemplate('Sendinblue Key'), () => {
testSecret(sendinblue.testcases)
})

it(testcaseTitleTemplate('Shippo Key'), () => {
testSecret(shippo.testcases)
})

it(testcaseTitleTemplate('Shopify Key'), () => {
testSecret(shopify.testcases)
})

it(testcaseTitleTemplate('Sidekiq Key'), () => {
testSecret(sidekiq.testcases)
})
Expand Down
13 changes: 11 additions & 2 deletions packages/secret-scan/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"strict": true,
"esModuleInterop": true
"esModuleInterop": true,

"moduleResolution": "node",
"isolatedModules": true,
"composite": false
},
"include": ["src/**/*.ts", "src/**/*.test.ts", "tsup.config.ts"],
"include": [
"src/**/*.ts",
"src/**/*.test.ts",
"tsup.config.ts",
"jest.config.js"
],
"exclude": ["node_modules", "dist"]
}
14 changes: 14 additions & 0 deletions packages/secret-scan/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/out-tsc",
"module": "ES2022",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
Loading

0 comments on commit ca8bf76

Please sign in to comment.