Merge pull request #1042 from enj/enj/i/group_warn_typo

Fix typo in group removed warning
This commit is contained in:
Mo Khan 2022-03-02 14:41:22 -05:00 committed by GitHub
commit dd4394a0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -416,12 +416,12 @@ func getDownstreamGroupsFromPinnipedSession(session *psession.PinnipedSession) (
return downstreamGroups, nil return downstreamGroups, nil
} }
func warnIfGroupsChanged(ctx context.Context, oldGroups []string, refreshedGroups []string, username string) { func warnIfGroupsChanged(ctx context.Context, oldGroups, newGroups []string, username string) {
added, removed := diffSortedGroups(oldGroups, refreshedGroups) added, removed := diffSortedGroups(oldGroups, newGroups)
if len(added) > 0 { if len(added) > 0 {
warning.AddWarning(ctx, "", fmt.Sprintf("User %q has been added to the following groups: %q", username, added)) warning.AddWarning(ctx, "", fmt.Sprintf("User %q has been added to the following groups: %q", username, added))
} }
if len(removed) > 0 { if len(removed) > 0 {
warning.AddWarning(ctx, "", fmt.Sprintf("User %q has been removed from the following groups: %q: ", username, removed)) warning.AddWarning(ctx, "", fmt.Sprintf("User %q has been removed from the following groups: %q", username, removed))
} }
} }

View File

@ -97,6 +97,11 @@ func TestSupervisorWarnings_Browser(t *testing.T) {
TLS: &authv1alpha.TLSSpec{CertificateAuthorityData: testCABundleBase64}, TLS: &authv1alpha.TLSSpec{CertificateAuthorityData: testCABundleBase64},
}) })
const (
yellowColor = "\u001b[33;1m"
resetColor = "\u001b[0m"
)
t.Run("LDAP group refresh flow", func(t *testing.T) { t.Run("LDAP group refresh flow", func(t *testing.T) {
if len(env.ToolsNamespace) == 0 && !env.HasCapability(testlib.CanReachInternetLDAPPorts) { if len(env.ToolsNamespace) == 0 && !env.HasCapability(testlib.CanReachInternetLDAPPorts) {
t.Skip("LDAP integration test requires connectivity to an LDAP server") t.Skip("LDAP integration test requires connectivity to an LDAP server")
@ -232,8 +237,8 @@ func TestSupervisorWarnings_Browser(t *testing.T) {
requireKubectlGetNamespaceOutput(t, env, string(kubectlPtyOutputBytes2)) requireKubectlGetNamespaceOutput(t, env, string(kubectlPtyOutputBytes2))
} }
// the output should include a warning that the groups have changed. // the output should include a warning that the groups have changed.
require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf("User %q has been added to the following groups: %q", env.SupervisorUpstreamLDAP.TestUserMailAttributeValue, env.SupervisorUpstreamLDAP.TestUserDirectGroupsDNs)) require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf(`%sWarning:%s User %q has been added to the following groups: %q`+"\r\n", yellowColor, resetColor, env.SupervisorUpstreamLDAP.TestUserMailAttributeValue, env.SupervisorUpstreamLDAP.TestUserDirectGroupsDNs))
require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf("User %q has been removed from the following groups: [\"some-other-group\" \"some-wrong-group\"]", env.SupervisorUpstreamLDAP.TestUserMailAttributeValue)) require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf(`%sWarning:%s User %q has been removed from the following groups: ["some-other-group" "some-wrong-group"]`+"\r\n", yellowColor, resetColor, env.SupervisorUpstreamLDAP.TestUserMailAttributeValue))
t.Logf("second kubectl command took %s", time.Since(startTime2).String()) t.Logf("second kubectl command took %s", time.Since(startTime2).String())
}) })
@ -431,8 +436,8 @@ func TestSupervisorWarnings_Browser(t *testing.T) {
requireKubectlGetNamespaceOutput(t, env, string(kubectlPtyOutputBytes2)) requireKubectlGetNamespaceOutput(t, env, string(kubectlPtyOutputBytes2))
} }
// the output should include a warning that the groups have changed. // the output should include a warning that the groups have changed.
require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf("User %q has been added to the following groups: %q", env.SupervisorUpstreamOIDC.Username, env.SupervisorUpstreamOIDC.ExpectedGroups)) require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf(`%sWarning:%s User %q has been added to the following groups: %q`+"\r\n", yellowColor, resetColor, env.SupervisorUpstreamOIDC.Username, env.SupervisorUpstreamOIDC.ExpectedGroups))
require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf("User %q has been removed from the following groups: [\"some-other-group\" \"some-wrong-group\"]", env.SupervisorUpstreamOIDC.Username)) require.Contains(t, string(kubectlPtyOutputBytes2), fmt.Sprintf(`%sWarning:%s User %q has been removed from the following groups: ["some-other-group" "some-wrong-group"]`+"\r\n", yellowColor, resetColor, env.SupervisorUpstreamOIDC.Username))
t.Logf("second kubectl command took %s", time.Since(startTime2).String()) t.Logf("second kubectl command took %s", time.Since(startTime2).String())
}) })