Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/twelve-sides-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

Fix `attributeMapping` field in the `CreateSamlConnectionParams` and `UpdateSamlConnectionParams` types.
144 changes: 144 additions & 0 deletions packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,148 @@ describe('SamlConnectionAPI', () => {
expect(response.totalCount).toBe(1);
});
});

describe('createSamlConnection', () => {
it('successfully creates a SAML connection', async () => {
const mockSamlConnectionResponse = {
object: 'saml_connection',
id: 'samlc_123',
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
organization_id: 'org_123',
created_at: 1672531200000,
updated_at: 1672531200000,
active: true,
sync_user_attributes: false,
allow_subdomains: false,
allow_idp_initiated: false,
idp_entity_id: 'entity_123',
idp_sso_url: 'https://idp.example.com/sso',
idp_certificate: 'cert_data',
idp_metadata_url: null,
idp_metadata: null,
attribute_mapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
};

server.use(
http.post(
'https://api.clerk.test/v1/saml_connections',
validateHeaders(async ({ request }) => {
const body = await request.json();

expect(body).toEqual({
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
attribute_mapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
});
return HttpResponse.json(mockSamlConnectionResponse);
}),
),
);

const response = await apiClient.samlConnections.createSamlConnection({
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
attributeMapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
});

expect(response.id).toBe('samlc_123');
expect(response.name).toBe('Test Connection');
expect(response.organizationId).toBe('org_123');
});
});

describe('updateSamlConnection', () => {
it('successfully updates a SAML connection', async () => {
const mockSamlConnectionResponse = {
object: 'saml_connection',
id: 'samlc_123',
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
organization_id: 'org_123',
created_at: 1672531200000,
updated_at: 1672531200000,
active: true,
sync_user_attributes: false,
allow_subdomains: false,
allow_idp_initiated: false,
idp_entity_id: 'entity_123',
idp_sso_url: 'https://idp.example.com/sso',
idp_certificate: 'cert_data',
idp_metadata_url: null,
idp_metadata: null,
attribute_mapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
};

server.use(
http.patch(
'https://api.clerk.test/v1/saml_connections/samlc_123',
validateHeaders(async ({ request }) => {
const body = await request.json();

expect(body).toEqual({
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
organization_id: 'org_123',
idp_entity_id: 'entity_123',
idp_sso_url: 'https://idp.example.com/sso',
idp_certificate: 'cert_data',
attribute_mapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
});
return HttpResponse.json(mockSamlConnectionResponse);
}),
),
);

const response = await apiClient.samlConnections.updateSamlConnection('samlc_123', {
name: 'Test Connection',
provider: 'saml_custom',
domain: 'test.example.com',
organizationId: 'org_123',
idpEntityId: 'entity_123',
idpSsoUrl: 'https://idp.example.com/sso',
idpCertificate: 'cert_data',
attributeMapping: {
user_id: 'userId',
email_address: 'email',
first_name: 'firstName',
last_name: 'lastName',
},
});

expect(response.id).toBe('samlc_123');
expect(response.name).toBe('Test Connection');
expect(response.organizationId).toBe('org_123');
});
});
});
17 changes: 9 additions & 8 deletions packages/backend/src/api/endpoints/SamlConnectionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ type CreateSamlConnectionParams = {
idpMetadataUrl?: string;
idpMetadata?: string;
attributeMapping?: {
emailAddress?: string;
firstName?: string;
lastName?: string;
userId?: string;
email_address?: string;
first_name?: string;
last_name?: string;
user_id?: string;
};
};

Expand All @@ -57,10 +57,10 @@ type UpdateSamlConnectionParams = {
idpMetadataUrl?: string;
idpMetadata?: string;
attributeMapping?: {
emailAddress?: string;
firstName?: string;
lastName?: string;
userId?: string;
email_address?: string;
first_name?: string;
last_name?: string;
user_id?: string;
};
active?: boolean;
syncUserAttributes?: boolean;
Expand Down Expand Up @@ -102,6 +102,7 @@ export class SamlConnectionAPI extends AbstractAPI {
bodyParams: params,
});
}

public async deleteSamlConnection(samlConnectionId: string) {
this.requireId(samlConnectionId);
return this.request<SamlConnection>({
Expand Down