Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TELAPPS-4794): expose user agent on login #343

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/js/src/Modules/Verto/messages/verto/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Login extends BaseRequest {
login_token,
userVariables,
loginParams: {},
'User-Agent': window.navigator.userAgent,
};
if (sessionid) {
params.sessid = sessionid;
Expand Down
24 changes: 21 additions & 3 deletions packages/js/src/Modules/Verto/tests/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Login, Invite, Answer, Bye, Modify, Info } from '../messages/Verto';
import { Ping } from '../messages/verto/Ping';
const userAgent = 'mock user agent';

describe('Messages', function () {
beforeAll(() => {
// Mocking the user agent for consistency
Object.defineProperty(window, 'navigator', {
value: { userAgent },
});
});
describe('Verto', function () {
describe('Login', function () {
it('should match struct', function () {
const message = new Login(
'login',
'password',
'dskbksdjbfkjsdf234y67234kjrwe98',
null
null!
).request;
const res = JSON.parse(
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","loginParams":{},"userVariables":{}}}`
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": "${userAgent}","login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","loginParams":{},"userVariables":{}}}`
);
expect(message).toEqual(res);
});
Expand All @@ -25,10 +32,21 @@ describe('Messages', function () {
'123456789'
).request;
const res = JSON.parse(
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","sessid":"123456789","loginParams":{},"userVariables":{}}}`
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": "${userAgent}","login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","sessid":"123456789","loginParams":{},"userVariables":{}}}`
);
expect(message).toEqual(res);
});

it('Should pass User-Agent to the backend', () => {
const req = new Login('login', 'password', 'token', 'session').request;
expect(req).toEqual(
expect.objectContaining({
params: expect.objectContaining({
'User-Agent': userAgent,
}),
})
);
});
});

describe('Invite', function () {
Expand Down
Loading