This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set user agent for Angular, React, Vue libs - plus Jest (#151)
Uses the new property in AuthJS to append the framework lib to the user agent Also adds unit testing via Jest for React, Vue Angular not yet tested, will add a "unit" test to app.component.spec.ts after #143 lands in master Add lniter to test in vue
- Loading branch information
1 parent
4c7400c
commit b95f27e
Showing
13 changed files
with
112 additions
and
10 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
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
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
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
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
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,11 @@ | ||
import Auth from '../../src/Auth'; | ||
|
||
const pkg = require('../../package.json'); | ||
|
||
test('Auth component sets the right user agent on AuthJS', () => { | ||
const auth = new Auth({ | ||
issuer: 'https://foo/oauth2/default' | ||
}); | ||
const expectedUserAgent = `${pkg.name}/${pkg.version} okta-auth-js-`; | ||
expect(auth._oktaAuth.userAgent).toMatch(expectedUserAgent); | ||
}); |
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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/config/ | ||
/dist/ | ||
/*.js | ||
src/packageInfo.js |
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
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
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
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,27 @@ | ||
import AuthJS from '@okta/okta-auth-js' | ||
import { createLocalVue } from '@vue/test-utils' | ||
import { default as Auth } from './Auth' | ||
|
||
const mockAuthJsInstance = {userAgent: 'foo'} | ||
const pkg = require('../package.json') | ||
|
||
jest.mock('@okta/okta-auth-js') | ||
|
||
AuthJS.mockImplementation(() => { | ||
return mockAuthJsInstance | ||
}) | ||
|
||
describe('Auth', () => { | ||
test('is a Vue plugin', () => { | ||
expect(Auth.install).toBeTruthy() | ||
}) | ||
test('sets the right user agent on AuthJS', () => { | ||
const expectedUserAgent = `${pkg.name}/${pkg.version} foo` | ||
createLocalVue().use(Auth, { | ||
issuer: '1', | ||
client_id: '2', | ||
redirect_uri: '3' | ||
}) | ||
expect(mockAuthJsInstance.userAgent).toMatch(expectedUserAgent) | ||
}) | ||
}) |
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,17 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const workingDirectory = process.argv[2]; | ||
const destinationFile = process.argv[3]; | ||
const packageJsonPath = path.join(process.cwd(), workingDirectory, 'package.json'); | ||
const configDest = path.join(process.cwd(), workingDirectory, destinationFile); | ||
const packageJson = require(packageJsonPath); | ||
const packageInfo = { | ||
name: packageJson.name, | ||
version: packageJson.version | ||
}; | ||
const output = 'export default ' + JSON.stringify(packageInfo, null, 2) + ';'; | ||
|
||
console.log('Writing config to', configDest); | ||
|
||
fs.writeFileSync(configDest, output); |