Skip to content

Commit 9f2e66a

Browse files
committed
fix: allow dry-run mode to bypass API token validation
Commands were failing in dry-run mode when no API token was present. The token validation occurred before the dry-run check, causing tests to fail with authentication errors even though dry-run should bail out early without requiring authentication. Updated checkCommandInput validation to allow dry-run mode to bypass token requirements by changing `test: hasApiToken` to `test: dryRun || hasApiToken` across all affected commands. Updated scan-github test expectations to reflect correct dry-run behavior where the command exits successfully after dry-run check rather than failing on missing token validation. Fixes 37 failing tests across analytics, audit-log, organization, package, repository, scan, and threat-feed commands.
1 parent b861231 commit 9f2e66a

26 files changed

+93
-52
lines changed

src/commands/analytics/cmd-analytics.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async function run(
167167
},
168168
{
169169
nook: true,
170-
test: hasApiToken,
170+
test: dryRun || hasApiToken,
171171
message: 'This command requires a Socket API token for access',
172172
fail: 'try `socket login`',
173173
},

src/commands/audit-log/cmd-audit-log.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async function run(
156156
},
157157
{
158158
nook: true,
159-
test: hasApiToken,
159+
test: dryRun || hasApiToken,
160160
message: 'This command requires a Socket API token for access',
161161
fail: 'try `socket login`',
162162
},

src/commands/fix/cmd-fix.integration.test.mts

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ describe('socket fix', async () => {
439439
async cmd => {
440440
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
441441
const output = stdout + stderr
442-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
442+
expect(output).toMatch(
443+
/Unable to resolve|An error was thrown while requesting/,
444+
)
443445
expect(code, 'should exit with non-zero code').not.toBe(0)
444446
},
445447
)
@@ -452,7 +454,9 @@ describe('socket fix', async () => {
452454
cwd: path.join(fixtureBaseDir, 'pnpm/vulnerable-deps'),
453455
})
454456
const output = stdout + stderr
455-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
457+
expect(output).toMatch(
458+
/Unable to resolve|An error was thrown while requesting/,
459+
)
456460
expect(code, 'should exit with non-zero code').not.toBe(0)
457461
},
458462
{ timeout: testTimeout },
@@ -466,7 +470,9 @@ describe('socket fix', async () => {
466470
cwd: path.join(fixtureBaseDir, 'pnpm/monorepo'),
467471
})
468472
const output = stdout + stderr
469-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
473+
expect(output).toMatch(
474+
/Unable to resolve|An error was thrown while requesting/,
475+
)
470476
expect(code, 'should exit with non-zero code').not.toBe(0)
471477
},
472478
{ timeout: testTimeout },
@@ -502,7 +508,9 @@ describe('socket fix', async () => {
502508
async cmd => {
503509
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
504510
const output = stdout + stderr
505-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
511+
expect(output).toMatch(
512+
/Unable to resolve|An error was thrown while requesting/,
513+
)
506514
expect(code, 'should exit with non-zero code').not.toBe(0)
507515
},
508516
)
@@ -513,7 +521,9 @@ describe('socket fix', async () => {
513521
async cmd => {
514522
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
515523
const output = stdout + stderr
516-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
524+
expect(output).toMatch(
525+
/Unable to resolve|An error was thrown while requesting/,
526+
)
517527
expect(code, 'should exit with non-zero code').not.toBe(0)
518528
},
519529
)
@@ -524,7 +534,9 @@ describe('socket fix', async () => {
524534
async cmd => {
525535
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
526536
const output = stdout + stderr
527-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
537+
expect(output).toMatch(
538+
/Unable to resolve|An error was thrown while requesting/,
539+
)
528540
expect(code, 'should exit with non-zero code').not.toBe(0)
529541
},
530542
)
@@ -542,7 +554,9 @@ describe('socket fix', async () => {
542554
async cmd => {
543555
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
544556
const output = stdout + stderr
545-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
557+
expect(output).toMatch(
558+
/Unable to resolve|An error was thrown while requesting/,
559+
)
546560
expect(code, 'should exit with non-zero code').not.toBe(0)
547561
},
548562
)
@@ -553,7 +567,9 @@ describe('socket fix', async () => {
553567
async cmd => {
554568
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
555569
const output = stdout + stderr
556-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
570+
expect(output).toMatch(
571+
/Unable to resolve|An error was thrown while requesting/,
572+
)
557573
expect(code, 'should exit with non-zero code').not.toBe(0)
558574
},
559575
)
@@ -564,7 +580,9 @@ describe('socket fix', async () => {
564580
async cmd => {
565581
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
566582
const output = stdout + stderr
567-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
583+
expect(output).toMatch(
584+
/Unable to resolve|An error was thrown while requesting/,
585+
)
568586
expect(code, 'should exit with non-zero code').not.toBe(0)
569587
},
570588
)
@@ -575,7 +593,9 @@ describe('socket fix', async () => {
575593
async cmd => {
576594
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
577595
const output = stdout + stderr
578-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
596+
expect(output).toMatch(
597+
/Unable to resolve|An error was thrown while requesting/,
598+
)
579599
expect(code, 'should exit with non-zero code').not.toBe(0)
580600
},
581601
)
@@ -596,7 +616,9 @@ describe('socket fix', async () => {
596616
cwd: path.join(fixtureBaseDir, 'pnpm/vulnerable-deps'),
597617
})
598618
const output = stdout + stderr
599-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
619+
expect(output).toMatch(
620+
/Unable to resolve|An error was thrown while requesting/,
621+
)
600622
expect(code, 'should exit with non-zero code').not.toBe(0)
601623
},
602624
)
@@ -616,7 +638,9 @@ describe('socket fix', async () => {
616638
cwd: path.join(fixtureBaseDir, 'pnpm/vulnerable-deps'),
617639
})
618640
const output = stdout + stderr
619-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
641+
expect(output).toMatch(
642+
/Unable to resolve|An error was thrown while requesting/,
643+
)
620644
expect(code, 'should exit with non-zero code').not.toBe(0)
621645
},
622646
)
@@ -638,7 +662,9 @@ describe('socket fix', async () => {
638662
cwd: path.join(fixtureBaseDir, 'pnpm/vulnerable-deps'),
639663
})
640664
const output = stdout + stderr
641-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
665+
expect(output).toMatch(
666+
/Unable to resolve|An error was thrown while requesting/,
667+
)
642668
expect(code, 'should exit with non-zero code').not.toBe(0)
643669
},
644670
)
@@ -662,7 +688,9 @@ describe('socket fix', async () => {
662688
cwd: path.join(fixtureBaseDir, 'pnpm/vulnerable-deps'),
663689
})
664690
const output = stdout + stderr
665-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
691+
expect(output).toMatch(
692+
/Unable to resolve|An error was thrown while requesting/,
693+
)
666694
expect(code, 'should exit with non-zero code').not.toBe(0)
667695
},
668696
)
@@ -685,7 +713,9 @@ describe('socket fix', async () => {
685713
cwd: path.join(fixtureBaseDir, 'pnpm/monorepo'),
686714
})
687715
const output = stdout + stderr
688-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
716+
expect(output).toMatch(
717+
/Unable to resolve|An error was thrown while requesting/,
718+
)
689719
expect(code, 'should exit with non-zero code').not.toBe(0)
690720
},
691721
)
@@ -703,7 +733,9 @@ describe('socket fix', async () => {
703733
async cmd => {
704734
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
705735
const output = stdout + stderr
706-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
736+
expect(output).toMatch(
737+
/Unable to resolve|An error was thrown while requesting/,
738+
)
707739
expect(code).toBeGreaterThan(0)
708740
},
709741
)
@@ -748,7 +780,9 @@ describe('socket fix', async () => {
748780
async cmd => {
749781
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
750782
const output = stdout + stderr
751-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
783+
expect(output).toMatch(
784+
/Unable to resolve|An error was thrown while requesting/,
785+
)
752786
expect(code).toBeGreaterThan(0)
753787
},
754788
{ timeout: testTimeout },
@@ -760,7 +794,9 @@ describe('socket fix', async () => {
760794
async cmd => {
761795
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
762796
const output = stdout + stderr
763-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
797+
expect(output).toMatch(
798+
/Unable to resolve|An error was thrown while requesting/,
799+
)
764800
expect(code).toBeGreaterThan(0)
765801
},
766802
{ timeout: testTimeout },
@@ -812,7 +848,9 @@ describe('socket fix', async () => {
812848
async cmd => {
813849
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
814850
const output = stdout + stderr
815-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
851+
expect(output).toMatch(
852+
/Unable to resolve|An error was thrown while requesting/,
853+
)
816854
expect(code).toBeGreaterThan(0)
817855
},
818856
)
@@ -954,7 +992,9 @@ describe('socket fix', async () => {
954992
async cmd => {
955993
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
956994
const output = stdout + stderr
957-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
995+
expect(output).toMatch(
996+
/Unable to resolve|An error was thrown while requesting/,
997+
)
958998
expect(code, 'should exit with non-zero code').not.toBe(0)
959999
},
9601000
)
@@ -1249,7 +1289,9 @@ describe('socket fix', async () => {
12491289
async cmd => {
12501290
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
12511291
const output = stdout + stderr
1252-
expect(output).toMatch(/Unable to resolve|An error was thrown while requesting/)
1292+
expect(output).toMatch(
1293+
/Unable to resolve|An error was thrown while requesting/,
1294+
)
12531295
expect(code, 'should exit with non-zero code').not.toBe(0)
12541296
},
12551297
)

src/commands/organization/cmd-organization-dependencies.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function run(
9494
},
9595
{
9696
nook: true,
97-
test: hasApiToken,
97+
test: dryRun || hasApiToken,
9898
message: 'This command requires a Socket API token for access',
9999
fail: 'try `socket login`',
100100
},

src/commands/organization/cmd-organization-list.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function run(
8383
},
8484
{
8585
nook: true,
86-
test: hasApiToken,
86+
test: dryRun || hasApiToken,
8787
message: 'This command requires a Socket API token for access',
8888
fail: 'try `socket login`',
8989
},

src/commands/organization/cmd-organization-policy-license.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function run(
106106
},
107107
{
108108
nook: true,
109-
test: hasApiToken,
109+
test: dryRun || hasApiToken,
110110
message: 'This command requires a Socket API token for access',
111111
fail: 'try `socket login`',
112112
},

src/commands/organization/cmd-organization-policy-security.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function run(
106106
},
107107
{
108108
nook: true,
109-
test: hasApiToken,
109+
test: dryRun || hasApiToken,
110110
message: 'This command requires a Socket API token for access',
111111
fail: 'try `socket login`',
112112
},

src/commands/organization/cmd-organization-quota.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function run(
7373
},
7474
{
7575
nook: true,
76-
test: hasApiToken,
76+
test: dryRun || hasApiToken,
7777
message: 'This command requires a Socket API token for access',
7878
fail: 'try `socket login`',
7979
},

src/commands/package/cmd-package-score.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async function run(
120120
},
121121
{
122122
nook: true,
123-
test: hasApiToken,
123+
test: dryRun || hasApiToken,
124124
message: 'This command requires a Socket API token for access',
125125
fail: 'try `socket login`',
126126
},

src/commands/repository/cmd-repository-create.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async function run(
141141
},
142142
{
143143
nook: true,
144-
test: hasApiToken,
144+
test: dryRun || hasApiToken,
145145
message: 'This command requires a Socket API token for access',
146146
fail: 'try `socket login`',
147147
},

0 commit comments

Comments
 (0)