nolint:bodyclose
(t *testing.T)
| 796 | |
| 797 | // nolint:bodyclose |
| 798 | func 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) { |
nothing calls this directly
no test coverage detected