Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/command/wrapper/socket-wrapper-addition.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function addSocketWrapper(file: string): Promise<void> {
`The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉`,
)
logger.log(
' If you want to disable it at any time, run `socket wrapper --disable`',
' If you want to disable it at any time, run `socket wrapper off`',
Comment thread
jdalton marked this conversation as resolved.
)
logger.log('')
logger.info(
Expand Down
54 changes: 53 additions & 1 deletion test/integration/cli/cmd-wrapper.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
* src/command/wrapper/handle-wrapper.mts - Wrapper management logic.
*/

import { promises as fs } from 'node:fs'
import os from 'node:os'
import path from 'node:path'

import { describe, expect } from 'vitest'
import { safeDelete } from '@socketsecurity/lib-stable/fs/safe'
import { describe, expect, it } from 'vitest'

import {
FLAG_CONFIG,
Expand All @@ -43,6 +46,55 @@ const fixtureHome = path.join(
const fixtureHomeEnv = { HOME: fixtureHome, USERPROFILE: fixtureHome }

describe('socket wrapper', async () => {
it('prints the supported command to disable the wrapper', async () => {
const temporaryHome = await fs.mkdtemp(
path.join(os.tmpdir(), 'socket-wrapper-'),
)
const profilePath = path.join(temporaryHome, '.bashrc')
const configDirectory = path.join(temporaryHome, 'config')
const env = {
HOME: temporaryHome,
USERPROFILE: temporaryHome,
XDG_CONFIG_HOME: configDirectory,
}

try {
await fs.mkdir(configDirectory)
await fs.writeFile(profilePath, '')

const enabled = await spawnSocketCli(
binCliPath,
['wrapper', 'on', FLAG_CONFIG, '{}'],
{ env },
)
expect(enabled.code).toBe(0)
expect(`${enabled.stdout}\n${enabled.stderr}`).toContain(
'`socket wrapper off`',
)
expect(`${enabled.stdout}\n${enabled.stderr}`).not.toContain(
'`socket wrapper --disable`',
)
expect(await fs.readFile(profilePath, 'utf8')).toContain(
'alias npm="socket npm"',
)

const disabled = await spawnSocketCli(
binCliPath,
['wrapper', 'off', FLAG_CONFIG, '{}'],
{ env },
)
expect(disabled.code).toBe(0)
expect(await fs.readFile(profilePath, 'utf8')).not.toContain(
'alias npm="socket npm"',
)
expect(await fs.readFile(profilePath, 'utf8')).not.toContain(
'alias npx="socket npx"',
)
} finally {
await safeDelete(temporaryHome)
}
})

cmdit(
['wrapper', FLAG_HELP, FLAG_CONFIG, '{}'],
`should support ${FLAG_HELP}`,
Expand Down
14 changes: 0 additions & 14 deletions test/unit/command/wrapper/socket-wrapper-addition.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ describe('addSocketWrapper', () => {
)
})

it('logs disable instructions', async () => {
await import('@socketsecurity/lib-stable/logger/default')
const fs = await import('node:fs')
const mockAppendFile = vi.mocked(fs.promises.appendFile)

mockAppendFile.mockResolvedValue(undefined)

await addSocketWrapper('/home/user/.bashrc')

expect(mockLogger.log).toHaveBeenCalledWith(
' If you want to disable it at any time, run `socket wrapper --disable`',
)
})

it('handles different shell config files', async () => {
const fs = await import('node:fs')
const mockAppendFile = vi.mocked(fs.promises.appendFile)
Expand Down
Loading