-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: UA string in Node no longer continuously extends (#1448)
OKTA-641280 fix: UA string in Node no longer continuously extends
- Loading branch information
1 parent
92826f6
commit ae12c07
Showing
18 changed files
with
173 additions
and
26 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
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
26 changes: 26 additions & 0 deletions
26
scripts/samples/e2e-express-embedded-auth-with-sdk-features.sh
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,26 @@ | ||
#!/bin/bash | ||
|
||
source $(dirname "${BASH_SOURCE[0]}")/../setup-e2e.sh | ||
|
||
# NOTE: this test suite runs against a separate test org on OK14 | ||
export USE_OK_14=1 | ||
setup_sample_tests | ||
|
||
export SAMPLE_NAME=@okta/samples.express-embedded-auth-with-sdk | ||
export MAX_INSTANCES=2 | ||
|
||
# NOTE: the command below evaluates to the same PASSWORD retrieved in setup-e2e, leaving commented just in case | ||
# get_vault_secret_key devex/prod-js-idx-sdk-vars password PASSWORD | ||
|
||
# based on run_sample_tests | ||
create_log_group "E2E Test Run" | ||
# Run the tests | ||
if ! yarn workspace @okta/test.e2e.samples test:features; then | ||
echo "tests failed! Exiting..." | ||
exit ${TEST_FAILURE} | ||
fi | ||
|
||
echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} | ||
echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} | ||
exit ${PUBLISH_TYPE_AND_RESULT_DIR} | ||
finish_log_group $? |
26 changes: 26 additions & 0 deletions
26
scripts/samples/e2e-express-embedded-auth-with-sdk-spec.sh
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,26 @@ | ||
#!/bin/bash | ||
|
||
source $(dirname "${BASH_SOURCE[0]}")/../setup-e2e.sh | ||
|
||
# NOTE: this test suite runs against a separate test org on OK14 | ||
export USE_OK_14=1 | ||
setup_sample_tests | ||
|
||
export SAMPLE_NAME=@okta/samples.express-embedded-auth-with-sdk | ||
export MAX_INSTANCES=2 | ||
|
||
# NOTE: the command below evaluates to the same PASSWORD retrieved in setup-e2e, leaving commented just in case | ||
# get_vault_secret_key devex/prod-js-idx-sdk-vars password PASSWORD | ||
|
||
# based on run_sample_tests | ||
create_log_group "E2E Test Run" | ||
# Run the tests | ||
if ! yarn workspace @okta/test.e2e.samples test:specs; then | ||
echo "tests failed! Exiting..." | ||
exit ${TEST_FAILURE} | ||
fi | ||
|
||
echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} | ||
echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} | ||
exit ${PUBLISH_TYPE_AND_RESULT_DIR} | ||
finish_log_group $? |
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 |
---|---|---|
@@ -1,63 +1,117 @@ | ||
const SDK_VERSION = (global as any).SDK_VERSION; | ||
const NODE_VERSION = (global as any).NODE_VERSION; | ||
|
||
import { OktaUserAgent } from '../../lib/http/OktaUserAgent'; | ||
|
||
jest.mock('../../lib/features', () => { | ||
const mocked = { | ||
isBrowser: jest.fn() | ||
}; | ||
jest.mock('lib/features', () => { | ||
return { | ||
isBrowser: () => {} | ||
__esModule: true, | ||
isBrowser: () => mocked.isBrowser() | ||
}; | ||
}); | ||
|
||
const mocked = { | ||
features: require('../../lib/features') | ||
}; | ||
|
||
describe('OktaUserAgent', () => { | ||
let oktaUserAgent; | ||
let sdkVersion; | ||
beforeEach(async () => { | ||
sdkVersion = (await import('../../package.json')).version; | ||
oktaUserAgent = new OktaUserAgent(); | ||
const context: any = {}; | ||
|
||
beforeEach(() => { | ||
context.oktaUserAgent = new OktaUserAgent(); | ||
}); | ||
|
||
describe('browser env', () => { | ||
beforeEach(() => { | ||
jest.spyOn(mocked.features, 'isBrowser').mockReturnValue(true); | ||
mocked.isBrowser.mockReturnValue(true); | ||
context.expected = `okta-auth-js/${SDK_VERSION}`; | ||
context.oktaUserAgent = new OktaUserAgent(); | ||
}); | ||
|
||
it('gets okta-auth-js and node info in the Okta UA by default', () => { | ||
const { oktaUserAgent, expected } = context; | ||
const httpHeader = oktaUserAgent.getHttpHeader(); | ||
expect(httpHeader).toEqual({ | ||
'X-Okta-User-Agent-Extended': `okta-auth-js/${sdkVersion}` | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
}); | ||
|
||
it('can add extra environment', () => { | ||
const { oktaUserAgent, expected } = context; | ||
oktaUserAgent.addEnvironment('fake/x.y'); | ||
const httpHeader = oktaUserAgent.getHttpHeader(); | ||
expect(httpHeader).toEqual({ | ||
'X-Okta-User-Agent-Extended': `okta-auth-js/${sdkVersion} fake/x.y` | ||
'X-Okta-User-Agent-Extended': `${expected} fake/x.y` | ||
}); | ||
}); | ||
|
||
// Reason: OKTA-641280 | ||
it('should return same header after multiple calls', () => { | ||
const { oktaUserAgent, expected } = context; | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
}); | ||
}); | ||
|
||
describe('node env', () => { | ||
let nodeVersion = process.versions.node; | ||
beforeEach(() => { | ||
jest.spyOn(mocked.features, 'isBrowser').mockReturnValue(false); | ||
mocked.isBrowser.mockReturnValue(false); | ||
context.expected = `okta-auth-js/${SDK_VERSION} nodejs/${NODE_VERSION}`; | ||
context.oktaUserAgent = new OktaUserAgent(); | ||
}); | ||
|
||
it('gets okta-auth-js and node info in the Okta UA by default', () => { | ||
const { oktaUserAgent, expected } = context; | ||
const httpHeader = oktaUserAgent.getHttpHeader(); | ||
expect(httpHeader).toEqual({ | ||
'X-Okta-User-Agent-Extended': `okta-auth-js/${sdkVersion} nodejs/${nodeVersion}` | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
}); | ||
|
||
it('can add extra environment', () => { | ||
const { oktaUserAgent, expected } = context; | ||
oktaUserAgent.addEnvironment('fake/x.y'); | ||
const httpHeader = oktaUserAgent.getHttpHeader(); | ||
expect(httpHeader).toEqual({ | ||
'X-Okta-User-Agent-Extended': `okta-auth-js/${sdkVersion} fake/x.y nodejs/${nodeVersion}` | ||
'X-Okta-User-Agent-Extended': `${expected} fake/x.y` | ||
}); | ||
}); | ||
|
||
// Reason: OKTA-641280 | ||
it('should return same header after multiple calls', () => { | ||
const { oktaUserAgent, expected } = context; | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
expect(oktaUserAgent.getHttpHeader()).toEqual({ | ||
'X-Okta-User-Agent-Extended': expected | ||
}); | ||
}); | ||
}); | ||
|
||
it('can get sdk version', () => { | ||
expect(oktaUserAgent.getVersion()).toBe(sdkVersion); | ||
const { oktaUserAgent } = context; | ||
expect(oktaUserAgent.getVersion()).toBe(SDK_VERSION); | ||
}); | ||
}); |
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