Skip to content

Commit f95e29f

Browse files
Handle 40 char tokens in SCIM token copy modal (#2955)
* fix scim token copy field * Set max width on message inside SCIM modal --------- Co-authored-by: Benjamin Leonard <benji@oxide.computer>
1 parent 9aacca0 commit f95e29f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

app/pages/system/silos/SiloScimTab.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default function SiloScimTab() {
9090
path: { tokenId: token.id },
9191
query: { silo: siloSelector.silo },
9292
}),
93+
resourceKind: 'SCIM token',
9394
label: token.id,
9495
}),
9596
},
@@ -234,19 +235,21 @@ function TokenCreatedModal({
234235
onDismiss: () => void
235236
}) {
236237
return (
237-
<Modal isOpen onDismiss={onDismiss} title="SCIM token created">
238+
<Modal isOpen onDismiss={onDismiss} title="SCIM token created" width="free">
238239
<Modal.Section>
239240
<Message
240241
variant="notice"
241-
content=<>
242-
This is the only time you’ll see this token. Copy it now and store it securely.
243-
</>
242+
content={
243+
<div className="max-w-md">
244+
You won’t see this token again. Copy it and store it securely.
245+
</div>
246+
}
244247
/>
245248

246249
<div className="mt-4">
247250
<div className="text-sans-md text-raise mb-2">Bearer Token</div>
248251
<div className="text-sans-md text-raise bg-default border-default flex items-stretch rounded border">
249-
<div className="flex-1 overflow-hidden px-3 py-2.75 text-ellipsis">
252+
<div className="flex-1 overflow-hidden py-2.75 pr-5 pl-3 text-nowrap text-ellipsis">
250253
{token.bearerToken}
251254
</div>
252255
<div className="border-default flex w-8 items-center justify-center border-l">

mock-api/msw/handlers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
ipRangeLen,
5454
NotImplemented,
5555
paginated,
56+
randomHex,
5657
requireFleetAdmin,
5758
requireFleetCollab,
5859
requireFleetViewer,
@@ -1903,12 +1904,9 @@ export const handlers = makeHandlers({
19031904
requireFleetCollab(cookies)
19041905
const silo = lookup.silo({ silo: query.silo })
19051906

1906-
// Generate a 20-character hex string
1907-
const hexString = uuid().replace(/-/g, '').slice(0, 20)
1908-
19091907
const newToken: Json<Api.ScimClientBearerTokenValue> = {
19101908
id: uuid(),
1911-
bearer_token: `oxide-scim-${hexString}`,
1909+
bearer_token: `oxide-scim-${randomHex(40)}`,
19121910
time_created: new Date().toISOString(),
19131911
}
19141912

mock-api/msw/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,10 @@ export function handleOxqlMetrics({ query }: TimeseriesQuery): Json<OxqlQueryRes
422422
const stateValue = getCpuStateFromQuery(query)
423423
return getMockOxqlInstanceData(metricName, stateValue)
424424
}
425+
426+
export function randomHex(length: number) {
427+
const hexChars = '0123456789abcdef'
428+
return Array.from({ length })
429+
.map(() => hexChars.charAt(Math.floor(Math.random() * hexChars.length)))
430+
.join('')
431+
}

test/e2e/scim-tokens.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ test('Create SCIM token', async ({ page }) => {
4141
await expect(tokenCreatedModal).toBeVisible()
4242

4343
// Check that the bearer token is visible and starts with oxide-scim-
44-
const bearerTokenDiv = tokenCreatedModal.getByText(/^oxide-scim-[a-f0-9]{20}$/)
44+
const bearerTokenDiv = tokenCreatedModal.getByText(/^oxide-scim-[a-f0-9]{40}$/)
4545
await expect(bearerTokenDiv).toBeVisible()
46-
const warning = tokenCreatedModal.getByText('This is the only')
46+
const warning = tokenCreatedModal.getByText('You won’t see this token again')
4747
await expect(warning).toBeVisible()
4848

4949
// Check that copy button is visible

0 commit comments

Comments
 (0)