1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
const MockRegistry = require('../../fixtures/mock-registry.js')
const username = 'foo'
const auth = { '//registry.npmjs.org/:_authToken': 'test-auth-token' }
t.test('npm whoami', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, { config: auth })
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
authorization: 'test-auth-token',
})
registry.whoami({ username })
await npm.exec('whoami', [])
t.equal(joinedOutput(), username, 'should print username')
})
t.test('npm whoami --json', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, {
config: {
json: true,
...auth,
},
})
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
authorization: 'test-auth-token',
})
registry.whoami({ username })
await npm.exec('whoami', [])
t.equal(JSON.parse(joinedOutput()), username, 'should print username')
})
t.test('npm whoami using mTLS', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, { config: {
'//registry.npmjs.org/:certfile': '/some.cert',
'//registry.npmjs.org/:keyfile': '/some.key',
} })
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})
registry.whoami({ username })
await npm.exec('whoami', [])
t.equal(joinedOutput(), username, 'should print username')
})
t.test('credentials from token', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, {
config: {
'//registry.npmjs.org/:username': username,
'//registry.npmjs.org/:_password': 'hunter2',
},
})
await npm.exec('whoami', [])
t.equal(joinedOutput(), username, 'should print username')
})
t.test('not logged in', async t => {
const { npm } = await loadMockNpm(t, {
config: {
json: true,
},
})
await t.rejects(npm.exec('whoami', []), { code: 'ENEEDAUTH' })
})
|