Skip to content

Commit 638b8d4

Browse files
authored
Merge pull request #262 from auth0/fix/sso-binding-methods
fix(react): use full saml urn format for sso binding methods
2 parents ec08048 + e3d00a9 commit 638b8d4

2 files changed

Lines changed: 111 additions & 3 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { screen, waitFor } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import React from 'react';
4+
import { vi, describe, it, expect, beforeEach } from 'vitest';
5+
6+
import type { SamlpConfigureFormHandle } from '@/components/auth0/my-organization/shared/idp-management/sso-provider-create/provider-configure/samlp-sso-configure-form';
7+
import { SamlpProviderForm } from '@/components/auth0/my-organization/shared/idp-management/sso-provider-create/provider-configure/samlp-sso-configure-form';
8+
import { createMockI18nService, renderWithProviders } from '@/tests/utils';
9+
10+
describe('SamlpProviderForm', () => {
11+
beforeEach(() => {
12+
vi.clearAllMocks();
13+
14+
createMockI18nService().translator('idp_management.create_sso_provider.provider_configure');
15+
});
16+
17+
describe('binding method', () => {
18+
describe('URN format', () => {
19+
it('should use full SAML URN format for default binding method value', async () => {
20+
const formRef = React.createRef<SamlpConfigureFormHandle>();
21+
renderWithProviders(<SamlpProviderForm ref={formRef} idpConfig={null} />);
22+
23+
await waitFor(() => {
24+
const data = formRef.current?.getData();
25+
expect(data?.bindingMethod).toBe('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST');
26+
});
27+
});
28+
29+
it('should preserve initial binding method value with full URN format', async () => {
30+
const formRef = React.createRef<SamlpConfigureFormHandle>();
31+
const initialData = {
32+
bindingMethod: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
33+
metadataUrl: 'https://example.com/metadata',
34+
};
35+
36+
renderWithProviders(
37+
<SamlpProviderForm ref={formRef} idpConfig={null} initialData={initialData} />,
38+
);
39+
40+
await waitFor(() => {
41+
const data = formRef.current?.getData();
42+
expect(data?.bindingMethod).toBe('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect');
43+
});
44+
});
45+
});
46+
47+
describe('rendering', () => {
48+
it('should render binding method field in advanced settings', async () => {
49+
const user = userEvent.setup();
50+
renderWithProviders(<SamlpProviderForm idpConfig={null} />);
51+
52+
const accordionTrigger = screen.getByRole('button', {
53+
name: 'fields.samlp.advanced_settings.title',
54+
});
55+
await user.click(accordionTrigger);
56+
57+
expect(
58+
screen.getByText('fields.samlp.advanced_settings.request_protocol_binding.label'),
59+
).toBeInTheDocument();
60+
});
61+
});
62+
});
63+
64+
describe('advanced settings', () => {
65+
describe('sign request', () => {
66+
it('should render signature algorithm fields when sign request is enabled', async () => {
67+
const user = userEvent.setup();
68+
renderWithProviders(<SamlpProviderForm idpConfig={null} />);
69+
70+
expect(
71+
screen.queryByText('fields.samlp.advanced_settings.sign_request_algorithm.label'),
72+
).not.toBeInTheDocument();
73+
74+
const accordionTrigger = screen.getByRole('button', {
75+
name: 'fields.samlp.advanced_settings.title',
76+
});
77+
await user.click(accordionTrigger);
78+
79+
const checkbox = screen.getByRole('checkbox');
80+
await user.click(checkbox);
81+
82+
expect(
83+
screen.getByText('fields.samlp.advanced_settings.sign_request_algorithm.label'),
84+
).toBeInTheDocument();
85+
expect(
86+
screen.getByText('fields.samlp.advanced_settings.sign_request_algorithm_digest.label'),
87+
).toBeInTheDocument();
88+
});
89+
});
90+
});
91+
92+
describe('form dirty state', () => {
93+
it('should call onFormDirty when form becomes dirty', async () => {
94+
const user = userEvent.setup();
95+
const onFormDirty = vi.fn();
96+
renderWithProviders(<SamlpProviderForm idpConfig={null} onFormDirty={onFormDirty} />);
97+
98+
const metadataUrlField = screen.getByPlaceholderText(
99+
'fields.samlp.meta_data_url.placeholder',
100+
);
101+
await user.type(metadataUrlField, 'https://example.com/metadata');
102+
103+
await waitFor(() => {
104+
expect(onFormDirty).toHaveBeenLastCalledWith(true);
105+
});
106+
});
107+
});
108+
});

packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-create/provider-configure/samlp-sso-configure-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const DIGEST_ALGORITHMS = [
6262
] as const;
6363

6464
const BINDING_METHODS = [
65-
{ value: 'HTTP-Redirect', label: 'HTTP-Redirect' },
66-
{ value: 'HTTP-POST', label: 'HTTP-POST' },
65+
{ value: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', label: 'HTTP-Redirect' },
66+
{ value: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST', label: 'HTTP-POST' },
6767
] as const;
6868

6969
export interface SamlpConfigureFormHandle {
@@ -103,7 +103,7 @@ export const SamlpProviderForm = React.forwardRef<
103103
signSAMLRequest: samlpData?.signSAMLRequest || false,
104104
signatureAlgorithm: samlpData?.signatureAlgorithm || 'rsa-sha256',
105105
digestAlgorithm: samlpData?.digestAlgorithm || 'sha256',
106-
bindingMethod: samlpData?.bindingMethod || 'HTTP-POST',
106+
bindingMethod: samlpData?.bindingMethod || 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
107107
},
108108
});
109109

0 commit comments

Comments
 (0)