Skip to content

Commit

Permalink
fix: Update useragent string with npm version (#13903)
Browse files Browse the repository at this point in the history
* update yarn lock and test

* Revert "fix: temporarily disable failing test to unblock pipeline"

This reverts commit 5960e13.

* remove char after + in userAgent version

* update unit tests

* revert integ test run

* update unit tests

* update lock
  • Loading branch information
ashika112 authored Oct 10, 2024
1 parent f648577 commit 541e463
Show file tree
Hide file tree
Showing 4 changed files with 1,666 additions and 1,740 deletions.
16 changes: 8 additions & 8 deletions .github/integ-config/integ-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,14 @@ tests:
browser: *minimal_browser_list

# GEO
# - test_name: integ_react_geo_display_map
# desc: 'Display Map'
# framework: react
# category: geo
# sample_name: [display-map]
# spec: display-map
# # Temp fix:
# browser: [chrome]
- test_name: integ_react_geo_display_map
desc: 'Display Map'
framework: react
category: geo
sample_name: [display-map]
spec: display-map
# Temp fix:
browser: [chrome]
- test_name: integ_react_geo_search_outside_map
desc: 'Search Outside Map'
framework: react
Expand Down
31 changes: 26 additions & 5 deletions packages/core/__tests__/Platform/userAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import {
Platform,
getAmplifyUserAgent,
getAmplifyUserAgentObject,
sanitizeAmplifyVersion,
} from '../../src/Platform';
import { version } from '../../src/Platform/version';
import { AuthAction, Category, Framework } from '../../src/Platform/types';
import {
clearCache,
detectFramework,
} from '../../src/Platform/detectFramework';
import * as detection from '../../src/Platform/detection';
import { getCustomUserAgent } from '../../src/Platform/customUserAgent';
import { version } from '../../src/Platform/version';

jest.mock('../../src/Platform/customUserAgent');
const expectedVersion = version.replace(/\+.*/, '');

describe('Platform test', () => {
const mockGetCustomUserAgent = getCustomUserAgent as jest.Mock;
Expand All @@ -36,10 +38,29 @@ describe('Platform test', () => {
});
});

describe('sanitizeAmplifyVersion', () => {
test('happy case with no special char', () => {
expect(sanitizeAmplifyVersion('6.6.0')).toEqual('6.6.0');
});

test('happy case with no special char +', () => {
expect(
sanitizeAmplifyVersion('6.6.4-unstable.ffa8a24.0+ffa8a24'),
).toEqual('6.6.4-unstable.ffa8a24.0');
});
});

describe('getAmplifyUserAgentObject test', () => {
test('without customUserAgentDetails', () => {
expect(getAmplifyUserAgentObject()).toStrictEqual([
['aws-amplify', version],
['aws-amplify', expectedVersion],
['framework', Framework.WebUnknown],
]);
});

test('should remove value after special char + in version', () => {
expect(getAmplifyUserAgentObject()).toStrictEqual([
['aws-amplify', expectedVersion],
['framework', Framework.WebUnknown],
]);
});
Expand All @@ -51,7 +72,7 @@ describe('Platform test', () => {
action: AuthAction.ConfirmSignIn,
}),
).toStrictEqual([
['aws-amplify', version],
['aws-amplify', expectedVersion],
[Category.Auth, AuthAction.ConfirmSignIn],
['framework', Framework.WebUnknown],
]);
Expand All @@ -68,7 +89,7 @@ describe('Platform test', () => {
action: AuthAction.ConfirmSignIn,
}),
).toStrictEqual([
['aws-amplify', version],
['aws-amplify', expectedVersion],
[Category.Auth, AuthAction.ConfirmSignIn],
['framework', Framework.WebUnknown],
['uiversion', '1.0.0'],
Expand Down Expand Up @@ -124,7 +145,7 @@ describe('Platform test', () => {
});

describe('detectFramework observers', () => {
let module;
let module: any;

beforeAll(() => {
jest.resetModules();
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/Platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import { getCustomUserAgent } from './customUserAgent';

const BASE_USER_AGENT = `aws-amplify`;

/** Sanitize Amplify version string be removing special character + and character post the special character */
export const sanitizeAmplifyVersion = (amplifyVersion: string) =>
amplifyVersion.replace(/\+.*/, '');

class PlatformBuilder {
userAgent = `${BASE_USER_AGENT}/${version}`;
userAgent = `${BASE_USER_AGENT}/${sanitizeAmplifyVersion(version)}`;
get framework() {
return detectFramework();
}
Expand All @@ -34,7 +38,10 @@ export const getAmplifyUserAgentObject = ({
category,
action,
}: CustomUserAgentDetails = {}): AWSUserAgent => {
const userAgent: AWSUserAgent = [[BASE_USER_AGENT, version]];
const userAgent: AWSUserAgent = [
[BASE_USER_AGENT, sanitizeAmplifyVersion(version)],
];

if (category) {
userAgent.push([category, action]);
}
Expand Down
Loading

0 comments on commit 541e463

Please sign in to comment.