-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from zendesk/rdemeterio/VEG-2359
[VEG-2359] - drop support for password based basic auth
- Loading branch information
Showing
15 changed files
with
196 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ yarn-error.log | |
packages/zcli-apps/tests/functional/mocks/*/tmp | ||
packages/**/dist | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import * as createAppUtils from '../../src/utils/createApp' | |
import * as appConfig from '../../src/utils/appConfig' | ||
import * as requestUtils from '../../../zcli-core/src/lib/requestUtils' | ||
import * as packageUtil from '../../src/lib/package' | ||
import env from './env' | ||
|
||
describe('apps', function () { | ||
const singleProductApp = path.join(__dirname, 'mocks/single_product_app') | ||
|
@@ -25,13 +26,10 @@ describe('apps', function () { | |
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.stub(createAppUtils, 'getManifestAppName', () => 'importantAppName') | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve('z3ntest')) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.stub(appConfig, 'setConfig', () => Promise.resolve()) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 817 }) | ||
|
@@ -67,11 +65,9 @@ describe('apps', function () { | |
describe('with single app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -97,11 +93,7 @@ describe('apps', function () { | |
describe('with requirements-only app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -126,11 +118,7 @@ describe('apps', function () { | |
describe('with single app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
@@ -153,11 +141,7 @@ describe('apps', function () { | |
describe('with requirements-only app', () => { | ||
test | ||
.stub(packageUtil, 'createAppPkg', () => createAppPkgStub) | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.env(env) | ||
.do(() => { | ||
createAppPkgStub.onFirstCall().resolves('thePathLessFrequentlyTravelled') | ||
uploadAppPkgStub.onFirstCall().resolves({ id: 819 }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_API_TOKEN: '123456' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ import * as path from 'path' | |
import * as fs from 'fs' | ||
import * as readline from 'readline' | ||
import * as AdmZip from 'adm-zip' | ||
import env from './env' | ||
import * as requestUtils from '../../../zcli-core/src/lib/requestUtils' | ||
|
||
describe('package', function () { | ||
const appPath = path.join(__dirname, 'mocks/single_product_app') | ||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.post('/api/v2/apps/validate') | ||
|
@@ -25,11 +25,9 @@ describe('package', function () { | |
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.post('/api/v2/apps/validate') | ||
|
@@ -69,11 +67,9 @@ describe('zcliignore', function () { | |
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.post('/api/v2/apps/validate') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { expect, test } from '@oclif/test' | ||
import * as path from 'path' | ||
import env from './env' | ||
import * as requestUtils from '../../../zcli-core/src/lib/requestUtils' | ||
|
||
describe('validate', function () { | ||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.post('/api/v2/apps/validate') | ||
|
@@ -20,11 +20,9 @@ describe('validate', function () { | |
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_SUBDOMAIN: 'z3ntest', | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' // the universal password | ||
}) | ||
.stub(requestUtils, 'getSubdomain', () => Promise.resolve(undefined)) | ||
.stub(requestUtils, 'getDomain', () => Promise.resolve(undefined)) | ||
.env(env) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.post('/api/v2/apps/validate') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,14 @@ import Auth from './auth' | |
import SecureStore from './secureStore' | ||
import { Profile } from '../types' | ||
|
||
const mockCreateBasicAuthToken = (...args: any[]) => { | ||
return `Basic ${args[0]}_${args[1]}_base64` | ||
} | ||
|
||
describe('Auth', () => { | ||
describe('createBasicAuthToken', () => { | ||
test | ||
.it('should create basic auth token', async () => { | ||
const auth = new Auth() | ||
expect( | ||
await auth.createBasicAuthToken('[email protected]', '123456') | ||
).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbToxMjM0NTY=') | ||
).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
}) | ||
}) | ||
|
||
|
@@ -35,24 +31,13 @@ describe('Auth', () => { | |
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_API_TOKEN: 'test_api_token' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should return basic token if ZENDESK_EMAIL and ZENDESK_API_TOKEN is set', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]/token_test_api_token_base64') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should return basic token if ZENDESK_EMAIL and ZENDESK_PASSWORD is set', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]_123456_base64') | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjp0ZXN0X2FwaV90b2tlbg==') | ||
}) | ||
|
||
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') | ||
}) | ||
|
@@ -74,10 +59,20 @@ describe('Auth', () => { | |
ZENDESK_API_TOKEN: 'test_api_token', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.it('should give precedence to ZENDESK_EMAIL and ZENDESK_API_TOKEN when ZENDESK_OAUTH_TOKEN is not defined', async () => { | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic [email protected]/token_test_api_token_base64') | ||
expect(await auth.getAuthorizationToken()).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjp0ZXN0X2FwaV90b2tlbg==') | ||
}) | ||
|
||
test | ||
.env({ | ||
ZENDESK_EMAIL: '[email protected]', | ||
ZENDESK_PASSWORD: '123456' | ||
}) | ||
.do(async () => { | ||
await auth.getAuthorizationToken() | ||
}) | ||
.catch(chalk.red('Basic authentication of type \'password\' is not supported.')) | ||
.it('should throw an error if only ZENDESK_EMAIL and ZENDESK_PASSWORD are set - basic auth with password not supported') | ||
}) | ||
|
||
describe('loginInteractively', () => { | ||
|
@@ -91,14 +86,13 @@ 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()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.zendesk.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
@@ -114,14 +108,13 @@ 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()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.example.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
@@ -136,14 +129,13 @@ 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()) | ||
.stub(auth, 'createBasicAuthToken', mockCreateBasicAuthToken) | ||
.nock('https://z3ntest.example.com', api => { | ||
api | ||
.get('/api/v2/account/settings.json') | ||
.reply(function () { | ||
expect(this.req.headers.authorization).to.equal('Basic [email protected]_123456_base64') | ||
expect(this.req.headers.authorization).to.equal('Basic dGVzdEB6ZW5kZXNrLmNvbS90b2tlbjoxMjM0NTY=') | ||
return [200] | ||
}) | ||
}) | ||
|
@@ -172,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) | ||
|
@@ -188,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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.