Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/fxa-shared/connected-services/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class ConnectedServicesFactory {
// We fill in a default device name from the OAuth client name,
// but individual clients can override this in their device record registration.
if (!client.name) {
client.name = oauthClient.client_name;
client.name = oauthClient.client_name ?? null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joi validation for this client.name explicitly allows null value (

name: DEVICES_SCHEMA.nameResponse
.allow('')
.allow(null)
.required(),
)

}
// For now we assume that all oauth clients that register a device record are mobile apps.
// Ref https://github.com/mozilla/fxa/issues/449
Expand Down Expand Up @@ -292,6 +292,6 @@ export class ConnectedServicesFactory {
}

protected getDefaultClientFields(): AttachedClient {
return attachedClientsDefaults;
return { ...attachedClientsDefaults };
}
}
18 changes: 18 additions & 0 deletions packages/fxa-shared/test/connected-services/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,23 @@ describe('connected-services/factories', () => {
Sinon.assert.calledOnce(bStubbed.oauthClients);
Sinon.assert.calledOnce(bStubbed.sessions);
});

it('handles undefined client_name without validation errors', async () => {
oauthClients = [
{
refresh_token_id: 'test-oauth',
created_time: Date.now(),
last_access_time: Date.now(),
client_name: undefined as any, // Simulate undefined from database
} as AttachedOAuthClient,
];
deviceList = [];
sessions = [];

const results = await factory.build('1234', 'en');

// Verify name is null, not undefined (required for validation)
assert.strictEqual(results[0].name, null);
});
});
});
Loading