Skip to content

Commit a4c138f

Browse files
committed
Updated unit tests, fixed lint issues and test workflows
1 parent 89c399c commit a4c138f

File tree

45 files changed

+3660
-2915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3660
-2915
lines changed

.github/workflows/unit-test.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,12 @@ jobs:
2222
node-version: '22.x'
2323
cache: 'pnpm' # optional but recommended
2424

25-
# - name: Temporarily disable contentstack package
26-
# run: mv packages/contentstack/package.json packages/contentstack/package.json.disabled || true
27-
2825
- name: Install Dependencies (Excluding Contentstack)
2926
run: pnpm install --frozen-lockfile
3027

3128
- name: Build all plugins (Excluding Contentstack)
3229
run: |
3330
NODE_ENV=PREPACK_MODE pnpm -r --sort run build
3431
35-
# - name: Restore contentstack package
36-
# run: mv packages/contentstack/package.json.disabled packages/contentstack/package.json || true
37-
38-
- name: Run tests for Contentstack Command
39-
working-directory: ./packages/contentstack-command
40-
run: npm run test:unit
41-
42-
- name: Run tests for Contentstack Config
43-
working-directory: ./packages/contentstack-config
44-
run: npm run test:unit
45-
46-
- name: Run tests for Contentstack Auth
47-
working-directory: ./packages/contentstack-auth
48-
run: NODE_ENV=PREPACK_MODE npm run test:unit
32+
- name: Run tests
33+
run: NODE_ENV=PREPACK_MODE pnpm test

.talismanrc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
fileignoreconfig:
2+
- filename: packages/contentstack-utilities/src/fs-utility/core.ts
3+
checksum: a3679bdc464c673ee5b53c2dd315cfda0e785bbb889a6fe33e61e8b34de17703
4+
- filename: packages/contentstack-auth/src/utils/mfa-handler.ts
5+
checksum: 723b1e69b2da51af73a7086e55a9ecedd4d1fd95855473eaa43a8375e0a92a7e
6+
- filename: packages/contentstack-utilities/src/logger/logger.ts
7+
checksum: ec84008d7715ccdfe32e32a4953b99bdb4c320f06ec411500858f87bf5b7db3c
8+
- filename: packages/contentstack-auth/test/unit/commands/tokens-add.test.ts
9+
checksum: d75044410ae06c75fb21ed06ac405854bd9a400fab15f74a0548c999bbdafaa3
10+
- filename: packages/contentstack-config/test/unit/commands/remove-base-branch.test.ts
11+
checksum: c7f98d87a9d686900781130f2c7684eaaf7d74869b79a2ab356140a2b6bf76b4
212
- filename: pnpm-lock.yaml
3-
checksum: 00d2cba7fffe932f86c5835d3dd23056a2055e6fa60d86175ca73710505b0d1d
4-
- filename: packages/contentstack-auth/src/commands/auth/logout.ts
5-
checksum: 20ff708d5a0ee56eb8786b19df07b49dacaddfa1deafe99c0397716c7865726d
13+
checksum: 53f754f5f8dc328c10809124fb190b2a5d2cdb090075f24928394b781d1eaed7
614
version: '1.0'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"inlcude": [
33
"lib/**/*.js"
4-
]
4+
],
5+
"concurrency": 1
56
}

packages/contentstack-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-auth/1.8.0-beta.0 darwin-arm64 node-v22.13.1
21+
@contentstack/cli-auth/1.8.0-beta.0 darwin-arm64 node-v24.13.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-auth/package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
"postpack": "rm -f oclif.manifest.json",
1212
"prepack": "pnpm compile && oclif manifest && oclif readme",
1313
"version": "oclif readme && git add README.md",
14-
"test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
15-
"pretest": "tsc -p test",
16-
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
17-
"posttest": "npm run lint",
1814
"lint": "eslint src/**/*.ts",
1915
"format": "eslint src/**/*.ts --fix",
20-
"test:integration": "mocha --forbid-only \"test/integration/*.test.ts\"",
21-
"test:unit": "mocha --forbid-only \"test/unit/**/*.test.ts\"",
22-
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
16+
"pretest": "tsc -p test",
17+
"test": "NODE_OPTIONS=--no-warnings nyc --concurrency=1 --extension .ts mocha --exit --forbid-only \"test/unit/**/*.test.ts\"",
18+
"test:report": "NODE_OPTIONS=--no-warnings nyc --concurrency=1 --extension .ts mocha --exit --forbid-only \"test/unit/**/*.test.ts\"",
19+
"posttest": "npm run lint"
2320
},
2421
"dependencies": {
2522
"@contentstack/cli-command": "~1.8.0-beta.0",

packages/contentstack-auth/src/utils/auth-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cliux, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
1+
import { cliux, log, messageHandler } from '@contentstack/cli-utilities';
22
import { User } from '../interfaces';
33
import { askOTPChannel, askOTP } from './interactive';
44

packages/contentstack-auth/src/utils/mfa-handler.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { cliux, configHandler, NodeCrypto, log, handleAndLogError, messageHandler } from '@contentstack/cli-utilities';
1+
import { cliux, configHandler, NodeCrypto, log } from '@contentstack/cli-utilities';
22
import { authenticator } from 'otplib';
3-
import { askOTP } from './interactive';
43

54
/**
65
* @class
@@ -66,7 +65,7 @@ class MFAHandler {
6665
* @returns Promise<string> The MFA code
6766
* @throws Error if MFA code generation fails
6867
*/
69-
async getMFACode(): Promise<string> {
68+
async getMFACode(): Promise<string | undefined> {
7069
log.debug('Getting MFA code', { module: 'mfa-handler' });
7170
let secret: string | undefined;
7271
let source: string;
@@ -87,6 +86,21 @@ class MFAHandler {
8786
}
8887
}
8988

89+
if (!secret) {
90+
const stored = configHandler.get('mfa') as { secret?: string } | undefined;
91+
if (stored?.secret) {
92+
try {
93+
const decrypted = this.encrypter.decrypt(stored.secret);
94+
if (decrypted && this.isValidBase32(decrypted.toUpperCase())) {
95+
secret = decrypted;
96+
source = 'stored configuration';
97+
}
98+
} catch {
99+
log.debug('Failed to decrypt stored MFA secret', { module: 'mfa-handler' });
100+
}
101+
}
102+
}
103+
90104
if (secret) {
91105
try {
92106
const code = this.generateMFACode(secret);
@@ -102,6 +116,16 @@ class MFAHandler {
102116
);
103117
}
104118
}
119+
return undefined;
120+
}
121+
122+
/**
123+
* Validates if a string is a valid 6-digit MFA code format
124+
* @param code The code to validate
125+
* @returns true if valid format, false otherwise
126+
*/
127+
isValidMFACode(code: string): boolean {
128+
return /^\d{6}$/.test(code);
105129
}
106130

107131
}

packages/contentstack-auth/test/integration/auth.test.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

packages/contentstack-auth/test/integration/config.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/contentstack-auth/test/integration/helper.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)