-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add application access section to the role editor
- Loading branch information
Showing
5 changed files
with
290 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,16 @@ import { createTeleportContext } from 'teleport/mocks/contexts'; | |
|
||
import { | ||
AccessSpec, | ||
AppAccessSpec, | ||
KubernetesAccessSpec, | ||
newAccessSpec, | ||
newRole, | ||
roleToRoleEditorModel, | ||
ServerAccessSpec, | ||
StandardEditorModel, | ||
} from './standardmodel'; | ||
import { | ||
AppAccessSpecSection, | ||
KubernetesAccessSpecSection, | ||
SectionProps, | ||
ServerAccessSpecSection, | ||
|
@@ -69,15 +72,19 @@ test('adding and removing sections', async () => { | |
await user.click( | ||
screen.getByRole('button', { name: 'Add New Specifications' }) | ||
); | ||
expect(getAllMenuItemNames()).toEqual(['Kubernetes', 'Servers']); | ||
expect(getAllMenuItemNames()).toEqual([ | ||
'Kubernetes', | ||
'Servers', | ||
'Applications', | ||
]); | ||
|
||
await user.click(screen.getByRole('menuitem', { name: 'Servers' })); | ||
expect(getAllSectionNames()).toEqual(['Role Metadata', 'Servers']); | ||
|
||
await user.click( | ||
screen.getByRole('button', { name: 'Add New Specifications' }) | ||
); | ||
expect(getAllMenuItemNames()).toEqual(['Kubernetes']); | ||
expect(getAllMenuItemNames()).toEqual(['Kubernetes', 'Applications']); | ||
|
||
await user.click(screen.getByRole('menuitem', { name: 'Kubernetes' })); | ||
expect(getAllSectionNames()).toEqual([ | ||
|
@@ -154,17 +161,13 @@ const StatefulSection = <S extends AccessSpec>({ | |
); | ||
}; | ||
|
||
test('editing server access specs', async () => { | ||
test('ServerAccessSpecSection', async () => { | ||
const user = userEvent.setup(); | ||
const onChange = jest.fn(); | ||
render( | ||
<StatefulSection<ServerAccessSpec> | ||
component={ServerAccessSpecSection} | ||
defaultValue={{ | ||
kind: 'node', | ||
labels: [], | ||
logins: [], | ||
}} | ||
defaultValue={newAccessSpec('node')} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
@@ -194,12 +197,7 @@ describe('KubernetesAccessSpecSection', () => { | |
render( | ||
<StatefulSection<KubernetesAccessSpec> | ||
component={KubernetesAccessSpecSection} | ||
defaultValue={{ | ||
kind: 'kube_cluster', | ||
groups: [], | ||
labels: [], | ||
resources: [], | ||
}} | ||
defaultValue={newAccessSpec('kube_cluster')} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
@@ -311,6 +309,49 @@ describe('KubernetesAccessSpecSection', () => { | |
}); | ||
}); | ||
|
||
test('AppAccessSpecSection', async () => { | ||
const user = userEvent.setup(); | ||
const onChange = jest.fn(); | ||
render( | ||
<StatefulSection<AppAccessSpec> | ||
component={AppAccessSpecSection} | ||
defaultValue={newAccessSpec('app')} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
await user.click(screen.getByRole('button', { name: 'Add a Label' })); | ||
await user.type(screen.getByPlaceholderText('label key'), 'env'); | ||
await user.type(screen.getByPlaceholderText('label value'), 'prod'); | ||
await user.type( | ||
within(screen.getByRole('group', { name: 'AWS Role ARNs' })).getByRole( | ||
'textbox' | ||
), | ||
'arn:aws:iam::123456789012:role/admin' | ||
); | ||
await user.type( | ||
within(screen.getByRole('group', { name: 'Azure Identities' })).getByRole( | ||
'textbox' | ||
), | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/admin' | ||
); | ||
await user.type( | ||
within( | ||
screen.getByRole('group', { name: 'GCP Service Accounts' }) | ||
).getByRole('textbox'), | ||
'[email protected]' | ||
); | ||
expect(onChange).toHaveBeenLastCalledWith({ | ||
kind: 'app', | ||
labels: [{ name: 'env', value: 'prod' }], | ||
awsRoleARNs: ['arn:aws:iam::123456789012:role/admin'], | ||
azureIdentities: [ | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/admin', | ||
], | ||
gcpServiceAccounts: ['[email protected]'], | ||
} as AppAccessSpec); | ||
}); | ||
|
||
const reactSelectValueContainer = (input: HTMLInputElement) => | ||
// eslint-disable-next-line testing-library/no-node-access | ||
input.closest('.react-select__value-container'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,76 @@ describe('roleToRoleEditorModel', () => { | |
], | ||
} as RoleEditorModel); | ||
}); | ||
|
||
it('creates an app access spec', () => { | ||
const minRole = minimalRole(); | ||
expect( | ||
roleToRoleEditorModel({ | ||
...minRole, | ||
spec: { | ||
...minRole.spec, | ||
allow: { | ||
app_labels: { foo: 'bar' }, | ||
}, | ||
}, | ||
}) | ||
).toEqual({ | ||
...minimalRoleModel(), | ||
accessSpecs: [ | ||
{ | ||
kind: 'app', | ||
labels: [{ name: 'foo', value: 'bar' }], | ||
awsRoleARNs: [], | ||
azureIdentities: [], | ||
gcpServiceAccounts: [], | ||
}, | ||
], | ||
} as RoleEditorModel); | ||
|
||
expect( | ||
roleToRoleEditorModel({ | ||
...minRole, | ||
spec: { | ||
...minRole.spec, | ||
allow: { | ||
app_labels: { foo: 'bar' }, | ||
aws_role_arns: [ | ||
'arn:aws:iam::123456789012:role/role1', | ||
'arn:aws:iam::123456789012:role/role2', | ||
], | ||
azure_identities: [ | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1', | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2', | ||
], | ||
gcp_service_accounts: [ | ||
'[email protected]', | ||
'[email protected]', | ||
], | ||
}, | ||
}, | ||
}) | ||
).toEqual({ | ||
...minimalRoleModel(), | ||
accessSpecs: [ | ||
{ | ||
kind: 'app', | ||
labels: [{ name: 'foo', value: 'bar' }], | ||
awsRoleARNs: [ | ||
'arn:aws:iam::123456789012:role/role1', | ||
'arn:aws:iam::123456789012:role/role2', | ||
], | ||
azureIdentities: [ | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1', | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2', | ||
], | ||
gcpServiceAccounts: [ | ||
'[email protected]', | ||
'[email protected]', | ||
], | ||
}, | ||
], | ||
} as RoleEditorModel); | ||
}); | ||
}); | ||
|
||
test('labelsToModel', () => { | ||
|
@@ -434,6 +504,53 @@ describe('roleEditorModelToRole', () => { | |
}, | ||
} as Role); | ||
}); | ||
|
||
it('converts an app access spec', () => { | ||
const minRole = minimalRole(); | ||
expect( | ||
roleEditorModelToRole({ | ||
...minimalRoleModel(), | ||
accessSpecs: [ | ||
{ | ||
kind: 'app', | ||
labels: [{ name: 'foo', value: 'bar' }], | ||
awsRoleARNs: [ | ||
'arn:aws:iam::123456789012:role/role1', | ||
'arn:aws:iam::123456789012:role/role2', | ||
], | ||
azureIdentities: [ | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1', | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2', | ||
], | ||
gcpServiceAccounts: [ | ||
'[email protected]', | ||
'[email protected]', | ||
], | ||
}, | ||
], | ||
}) | ||
).toEqual({ | ||
...minRole, | ||
spec: { | ||
...minRole.spec, | ||
allow: { | ||
app_labels: { foo: 'bar' }, | ||
aws_role_arns: [ | ||
'arn:aws:iam::123456789012:role/role1', | ||
'arn:aws:iam::123456789012:role/role2', | ||
], | ||
azure_identities: [ | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1', | ||
'/subscriptions/1020304050607-cafe-8090-a0b0c0d0e0f0/resourceGroups/example-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2', | ||
], | ||
gcp_service_accounts: [ | ||
'[email protected]', | ||
'[email protected]', | ||
], | ||
}, | ||
}, | ||
} as Role); | ||
}); | ||
}); | ||
|
||
test('labelsModelToLabels', () => { | ||
|
Oops, something went wrong.