MCPcopy Index your code
hub / github.com/coder/coder / TestGroupSync

Function TestGroupSync

enterprise/coderd/userauth_test.go:798–1000  ·  view source on GitHub ↗

nolint:bodyclose

(t *testing.T)

Source from the content-addressed store, hash-verified

796
797// nolint:bodyclose
798func TestGroupSync(t *testing.T) {
799 t.Parallel()
800
801 testCases := []struct {
802 name string
803 modCfg func(cfg *coderd.OIDCConfig)
804 modDV func(dv *codersdk.DeploymentValues)
805 // initialOrgGroups is initial groups in the org
806 initialOrgGroups []string
807 // initialUserGroups is initial groups for the user
808 initialUserGroups []string
809 // expectedUserGroups is expected groups for the user
810 expectedUserGroups []string
811 // expectedOrgGroups is expected all groups on the system
812 expectedOrgGroups []string
813 claims jwt.MapClaims
814 }{
815 {
816 name: "NoGroups",
817 modCfg: func(cfg *coderd.OIDCConfig) {
818 },
819 initialOrgGroups: []string{},
820 expectedUserGroups: []string{},
821 expectedOrgGroups: []string{},
822 claims: jwt.MapClaims{},
823 },
824 {
825 name: "GroupSyncDisabled",
826 modDV: func(dv *codersdk.DeploymentValues) {
827 // Disable group sync
828 dv.OIDC.GroupField = ""
829 dv.OIDC.GroupRegexFilter = serpent.Regexp(*regexp.MustCompile(".*"))
830 },
831 initialOrgGroups: []string{"a", "b", "c", "d"},
832 initialUserGroups: []string{"b", "c", "d"},
833 expectedUserGroups: []string{"b", "c", "d"},
834 expectedOrgGroups: []string{"a", "b", "c", "d"},
835 claims: jwt.MapClaims{},
836 },
837 {
838 // From a,c,b -> b,c,d
839 name: "ChangeUserGroups",
840 modDV: func(dv *codersdk.DeploymentValues) {
841 dv.OIDC.GroupMapping = serpent.Struct[map[string]string]{Value: map[string]string{"D": "d"}}
842 },
843 initialOrgGroups: []string{"a", "b", "c", "d"},
844 initialUserGroups: []string{"a", "b", "c"},
845 expectedUserGroups: []string{"b", "c", "d"},
846 expectedOrgGroups: []string{"a", "b", "c", "d"},
847 claims: jwt.MapClaims{
848 // D -> d mapped
849 "groups": []string{"b", "c", "D"},
850 },
851 },
852 {
853 // From a,c,b -> []
854 name: "RemoveAllGroups",
855 modDV: func(dv *codersdk.DeploymentValues) {

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
CreateAnotherUserFunction · 0.92
AsSystemRestrictedFunction · 0.92
ContainsFunction · 0.92
ContainsCompareFunction · 0.92
setupOIDCTestFunction · 0.85
MustCompileMethod · 0.80
CreateGroupMethod · 0.80
PatchGroupMethod · 0.80
GroupsByOrganizationMethod · 0.80
RunMethod · 0.65
UpdateUserLoginTypeMethod · 0.65

Tested by

no test coverage detected