-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support SAML app encryption and nameIdFormat config (#6912)
- Loading branch information
Showing
7 changed files
with
166 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/schemas/alterations/next-1735274337-add-encryption-config-to-saml-apps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
enum NameIdFormat { | ||
/** Uses unique and persistent identifiers for the user. */ | ||
Persistent = 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', | ||
} | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
await pool.query(sql` | ||
alter table saml_application_configs | ||
add column encryption jsonb, | ||
add column name_id_format varchar(128); | ||
`); | ||
await pool.query(sql` | ||
update saml_application_configs | ||
set name_id_format = ${NameIdFormat.Persistent}; | ||
`); | ||
await pool.query(sql` | ||
alter table saml_application_configs | ||
alter column name_id_format set not null; | ||
`); | ||
}, | ||
down: async (pool) => { | ||
await pool.query(sql` | ||
alter table saml_application_configs | ||
drop column encryption, | ||
drop column name_id_format; | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |
61 changes: 61 additions & 0 deletions
61
packages/schemas/src/foundations/jsonb-types/saml-application-configs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { samlEncryptionGuard } from './saml-application-configs.js'; | ||
|
||
describe('samlEncryptionGuard', () => { | ||
// Test valid configurations | ||
it('should pass when encryption is disabled', () => { | ||
const result = samlEncryptionGuard.safeParse({ | ||
encryptAssertion: false, | ||
}); | ||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('should pass when encryption is enabled with all required fields', () => { | ||
const result = samlEncryptionGuard.safeParse({ | ||
encryptAssertion: true, | ||
encryptThenSign: true, | ||
certificate: '-----BEGIN CERTIFICATE-----\nMIICYDCCAcmgAwIBA...', | ||
}); | ||
expect(result.success).toBe(true); | ||
}); | ||
|
||
// Test invalid configurations | ||
it('should fail when encryptAssertion is true but missing encryptThenSign', () => { | ||
const result = samlEncryptionGuard.safeParse({ | ||
encryptAssertion: true, | ||
certificate: '-----BEGIN CERTIFICATE-----\nMIICYDCCAcmgAwIBA...', | ||
}); | ||
expect(result.success).toBe(false); | ||
if (!result.success) { | ||
expect(result.error.issues[0]?.message).toBe( | ||
'`encryptThenSign` and `certificate` are required when `encryptAssertion` is `true`' | ||
); | ||
} | ||
}); | ||
|
||
it('should fail when encryptAssertion is true but missing certificate', () => { | ||
const result = samlEncryptionGuard.safeParse({ | ||
encryptAssertion: true, | ||
encryptThenSign: true, | ||
}); | ||
expect(result.success).toBe(false); | ||
if (!result.success) { | ||
expect(result.error.issues[0]?.message).toBe( | ||
'`encryptThenSign` and `certificate` are required when `encryptAssertion` is `true`' | ||
); | ||
} | ||
}); | ||
|
||
it('should fail when encryptAssertion is true but missing both encryptThenSign and certificate', () => { | ||
const result = samlEncryptionGuard.safeParse({ | ||
encryptAssertion: true, | ||
}); | ||
expect(result.success).toBe(false); | ||
if (!result.success) { | ||
expect(result.error.issues[0]?.message).toBe( | ||
'`encryptThenSign` and `certificate` are required when `encryptAssertion` is `true`' | ||
); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters