Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(token): properly await registry request #7385

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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 lib/commands/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Token extends BaseCommand {
async list () {
const conf = this.config()
log.info('token', 'getting list')
const tokens = profile.listTokens(conf)
const tokens = await profile.listTokens(conf)
if (conf.json) {
output.standard(JSON.stringify(tokens, null, 2))
return
Expand Down
36 changes: 18 additions & 18 deletions test/lib/commands/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ t.test('token list', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: conf => {
listTokens: async conf => {
t.same(conf.auth, { token: 'thisisnotarealtoken', otp: '123456' })
return tokens
},
Expand Down Expand Up @@ -118,7 +118,7 @@ t.test('token list json output', async t => {
return { username: 'foo', password: 'bar' }
},
profile: {
listTokens: conf => {
listTokens: async conf => {
t.same(
conf.auth,
{ basic: { username: 'foo', password: 'bar' } },
Expand Down Expand Up @@ -164,7 +164,7 @@ t.test('token list parseable output', async t => {
return { auth: Buffer.from('foo:bar').toString('base64') }
},
profile: {
listTokens: conf => {
listTokens: async conf => {
t.same(
conf.auth,
{ basic: { username: 'foo', password: 'bar' } },
Expand Down Expand Up @@ -212,11 +212,11 @@ t.test('token revoke', async t => {
return {}
},
profile: {
listTokens: conf => {
listTokens: async conf => {
t.same(conf.auth, {}, 'passes the correct empty auth')
return Promise.resolve([{ key: 'abcd1234' }])
},
removeToken: key => {
removeToken: async key => {
t.equal(key, 'abcd1234', 'deletes the correct token')
},
},
Expand All @@ -235,8 +235,8 @@ t.test('token revoke multiple tokens', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234' }, { key: 'efgh5678' }]),
removeToken: key => {
listTokens: async () => ([{ key: 'abcd1234' }, { key: 'efgh5678' }]),
removeToken: async key => {
// this will run twice
t.ok(['abcd1234', 'efgh5678'].includes(key), 'deletes the correct token')
},
Expand All @@ -256,8 +256,8 @@ t.test('token revoke json output', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234' }]),
removeToken: key => {
listTokens: async () => ([{ key: 'abcd1234' }]),
removeToken: async key => {
t.equal(key, 'abcd1234', 'deletes the correct token')
},
},
Expand All @@ -278,8 +278,8 @@ t.test('token revoke parseable output', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234' }]),
removeToken: key => {
listTokens: async () => ([{ key: 'abcd1234' }]),
removeToken: async key => {
t.equal(key, 'abcd1234', 'deletes the correct token')
},
},
Expand All @@ -298,8 +298,8 @@ t.test('token revoke by token', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234', token: 'efgh5678' }]),
removeToken: key => {
listTokens: async () => ([{ key: 'abcd1234', token: 'efgh5678' }]),
removeToken: async key => {
t.equal(key, 'efgh5678', 'passes through user input')
},
},
Expand All @@ -323,7 +323,7 @@ t.test('token revoke ambiguous id errors', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234' }, { key: 'abcd5678' }]),
listTokens: async () => ([{ key: 'abcd1234' }, { key: 'abcd5678' }]),
},
})

Expand All @@ -338,7 +338,7 @@ t.test('token revoke unknown id errors', async t => {
return { token: 'thisisnotarealtoken' }
},
profile: {
listTokens: () => Promise.resolve([{ key: 'abcd1234' }]),
listTokens: async () => ([{ key: 'abcd1234' }]),
},
})

Expand All @@ -362,7 +362,7 @@ t.test('token create', async t => {
password: () => Promise.resolve(password),
},
profile: {
createToken: (pw, readonly, cidr) => {
createToken: async (pw, readonly, cidr) => {
t.equal(pw, password)
t.equal(readonly, false)
t.same(cidr, ['10.0.0.0/8', '192.168.1.0/24'], 'defaults to empty array')
Expand Down Expand Up @@ -405,7 +405,7 @@ t.test('token create json output', async t => {
password: () => Promise.resolve(password),
},
profile: {
createToken: (pw, readonly, cidr) => {
createToken: async (pw, readonly, cidr) => {
t.equal(pw, password)
t.equal(readonly, false)
t.same(cidr, [], 'defaults to empty array')
Expand Down Expand Up @@ -447,7 +447,7 @@ t.test('token create parseable output', async t => {
password: () => Promise.resolve(password),
},
profile: {
createToken: (pw, readonly, cidr) => {
createToken: async (pw, readonly, cidr) => {
t.equal(pw, password)
t.equal(readonly, false)
t.same(cidr, [], 'defaults to empty array')
Expand Down
Loading