Skip to content

Commit

Permalink
feat: replace term password with secret
Browse files Browse the repository at this point in the history
To keep things generic. However, we can't change the keytar interface as these fucntion names are library requirements.
  • Loading branch information
romeodemeteriojr committed Jul 11, 2024
1 parent e4eb869 commit e0c2aaa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/zcli-core/src/lib/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Auth', () => {

test
.stub(auth, 'getLoggedInProfile', () => ({ subdomain: 'z3ntest' }))
.stub(auth.secureStore, 'getPassword', () => 'Basic test_token')
.stub(auth.secureStore, 'getSecret', () => 'Basic test_token')
.it('should return token stored in secure store if no env vars are set', async () => {
expect(await auth.getAuthorizationToken()).to.equal('Basic test_token')
})
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Auth', () => {
promptStub.onThirdCall().resolves('123456')
})
.stub(CliUx.ux, 'prompt', () => promptStub)
.stub(auth.secureStore, 'setPassword', () => Promise.resolve())
.stub(auth.secureStore, 'setSecret', () => Promise.resolve())
.stub(auth, 'setLoggedInProfile', () => Promise.resolve())
.nock('https://z3ntest.zendesk.com', api => {
api
Expand All @@ -108,7 +108,7 @@ describe('Auth', () => {
promptStub.onThirdCall().resolves('123456')
})
.stub(CliUx.ux, 'prompt', () => promptStub)
.stub(auth.secureStore, 'setPassword', () => Promise.resolve())
.stub(auth.secureStore, 'setSecret', () => Promise.resolve())
.stub(auth, 'setLoggedInProfile', () => Promise.resolve())
.nock('https://z3ntest.example.com', api => {
api
Expand All @@ -129,7 +129,7 @@ describe('Auth', () => {
promptStub.onSecondCall().resolves('123456')
})
.stub(CliUx.ux, 'prompt', () => promptStub)
.stub(auth.secureStore, 'setPassword', () => Promise.resolve())
.stub(auth.secureStore, 'setSecret', () => Promise.resolve())
.stub(auth, 'setLoggedInProfile', () => Promise.resolve())
.nock('https://z3ntest.example.com', api => {
api
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Auth', () => {

test
.stub(auth, 'getLoggedInProfile', () => ({ subdomain: 'z3ntest' }))
.stub(auth.secureStore, 'deletePassword', () => Promise.resolve(true))
.stub(auth.secureStore, 'deleteSecret', () => Promise.resolve(true))
.stub(auth.config, 'removeConfig', () => Promise.resolve())
.it('should return true on logout success', async () => {
expect(await auth.logout()).to.equal(true)
Expand All @@ -180,7 +180,7 @@ describe('Auth', () => {

test
.stub(auth, 'getLoggedInProfile', () => ({ subdomain: 'z3ntest' }))
.stub(auth.secureStore, 'deletePassword', () => Promise.resolve(false))
.stub(auth.secureStore, 'deleteSecret', () => Promise.resolve(false))
.stub(auth.config, 'removeConfig', () => Promise.resolve())
.do(async () => {
await auth.logout()
Expand Down
6 changes: 3 additions & 3 deletions packages/zcli-core/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Auth {
} else {
const profile = await this.getLoggedInProfile()
if (profile && this.secureStore) {
const authToken = await this.secureStore.getPassword(getAccount(profile.subdomain, profile.domain))
const authToken = await this.secureStore.getSecret(getAccount(profile.subdomain, profile.domain))
return authToken
}

Expand Down Expand Up @@ -79,7 +79,7 @@ export default class Auth {
})

if (testAuth.status === 200 && this.secureStore) {
await this.secureStore.setPassword(account, authToken)
await this.secureStore.setSecret(account, authToken)
await this.setLoggedInProfile(subdomain, domain)

return true
Expand All @@ -96,7 +96,7 @@ export default class Auth {
const profile = await this.getLoggedInProfile()
if (!profile?.subdomain) throw new CLIError(chalk.red('Failed to log out: no active profile found.'))
await this.config.removeConfig('activeProfile')
const deleted = await this.secureStore.deletePassword(getAccount(profile.subdomain, profile.domain))
const deleted = await this.secureStore.deleteSecret(getAccount(profile.subdomain, profile.domain))
if (!deleted) throw new CLIError(chalk.red('Failed to log out: Account, Service not found.'))

return true
Expand Down
8 changes: 4 additions & 4 deletions packages/zcli-core/src/lib/secureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export default class SecureStore {
return this.keytar
}

setPassword (account: string, password: string) {
return this.keytar?.setPassword(this.serviceName, account, password)
setSecret (account: string, secret: string) {
return this.keytar?.setPassword(this.serviceName, account, secret)
}

getPassword (account: string) {
getSecret (account: string) {
return this.keytar?.getPassword(this.serviceName, account)
}

deletePassword (account: string) {
deleteSecret (account: string) {
return this.keytar?.deletePassword(this.serviceName, account)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zcli/src/commands/profiles/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Remove extends Command {
return
}

const deleted = await secureStore.deletePassword(account)
const deleted = await secureStore.deleteSecret(account)
if (!deleted) throw new CLIError(chalk.red(`Profile ${account} not found.`))
console.log(chalk.green(`Removed ${account} profile.`))
}
Expand Down

0 comments on commit e0c2aaa

Please sign in to comment.