Skip to content

Commit 3ea481e

Browse files
committed
message tweaks for kube
1 parent aae0e22 commit 3ea481e

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

pkg/cmd/server/kubernetes/master/master_config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var expectedGroupPreferredVersions []string = []string{
3535
"admissionregistration.k8s.io/v1alpha1",
3636
"apps/v1beta1,authentication.k8s.io/v1",
3737
"authorization.k8s.io/v1",
38+
"authorization.openshift.io/v1",
3839
"autoscaling/v1",
3940
"batch/v1",
4041
"certificates.k8s.io/v1beta1",

test/cmd/authentication.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,29 @@ os::cmd::expect_success "oc policy can-i --list"
4747
whoamitoken="$(oc process -f "${OS_ROOT}/test/testdata/authentication/scoped-token-template.yaml" TOKEN_PREFIX=whoami SCOPE=user:info USER_NAME="${username}" USER_UID="${useruid}" | oc create -f - -o name | awk -F/ '{print $2}')"
4848
os::cmd::expect_success_and_text "oc get user/~ --token='${whoamitoken}'" "${username}"
4949
os::cmd::expect_success_and_text "oc whoami --token='${whoamitoken}'" "${username}"
50-
os::cmd::expect_failure_and_text "oc get pods --token='${whoamitoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list pods in project \"${project}\""
50+
os::cmd::expect_failure_and_text "oc get pods --token='${whoamitoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list pods in the namespace \"${project}\""
5151

5252
listprojecttoken="$(oc process -f "${OS_ROOT}/test/testdata/authentication/scoped-token-template.yaml" TOKEN_PREFIX=listproject SCOPE=user:list-scoped-projects USER_NAME="${username}" USER_UID="${useruid}" | oc create -f - -o name | awk -F/ '{print $2}')"
5353
# this token doesn't have rights to see any projects even though it can hit the list endpoint, so an empty list is correct
5454
# we'll add another scope that allows listing all known projects even if this token has no other powers in them.
5555
os::cmd::expect_success_and_not_text "oc get projects --token='${listprojecttoken}'" "${project}"
5656
os::cmd::expect_failure_and_text "oc get user/~ --token='${listprojecttoken}'" 'prevent this action; User "scoped-user" cannot get users at the cluster scope'
57-
os::cmd::expect_failure_and_text "oc get pods --token='${listprojecttoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list pods in project \"${project}\""
57+
os::cmd::expect_failure_and_text "oc get pods --token='${listprojecttoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list pods in the namespace \"${project}\""
5858

5959
listprojecttoken="$(oc process -f "${OS_ROOT}/test/testdata/authentication/scoped-token-template.yaml" TOKEN_PREFIX=listallprojects SCOPE=user:list-projects USER_NAME="${username}" USER_UID="${useruid}" | oc create -f - -o name | awk -F/ '{print $2}')"
6060
os::cmd::expect_success_and_text "oc get projects --token='${listprojecttoken}'" "${project}"
6161

6262
adminnonescalatingpowerstoken="$(oc process -f "${OS_ROOT}/test/testdata/authentication/scoped-token-template.yaml" TOKEN_PREFIX=admin SCOPE=role:admin:* USER_NAME="${username}" USER_UID="${useruid}" | oc create -f - -o name | awk -F/ '{print $2}')"
6363
os::cmd::expect_failure_and_text "oc get user/~ --token='${adminnonescalatingpowerstoken}'" 'prevent this action; User "scoped-user" cannot get users at the cluster scope'
64-
os::cmd::expect_failure_and_text "oc get secrets --token='${adminnonescalatingpowerstoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list secrets in project \"${project}\""
64+
os::cmd::expect_failure_and_text "oc get secrets --token='${adminnonescalatingpowerstoken}' -n '${project}'" "prevent this action; User \"scoped-user\" cannot list secrets in the namespace \"${project}\""
6565
os::cmd::expect_success_and_text "oc get 'projects/${project}' --token='${adminnonescalatingpowerstoken}' -n '${project}'" "${project}"
6666

6767
allescalatingpowerstoken="$(oc process -f "${OS_ROOT}/test/testdata/authentication/scoped-token-template.yaml" TOKEN_PREFIX=clusteradmin SCOPE='role:cluster-admin:*:!' USER_NAME="${username}" USER_UID="${useruid}" | oc create -f - -o name | awk -F/ '{print $2}')"
6868
os::cmd::expect_success_and_text "oc get user/~ --token='${allescalatingpowerstoken}'" "${username}"
6969
os::cmd::expect_success "oc get secrets --token='${allescalatingpowerstoken}' -n '${project}'"
7070
# scopes allow it, but authorization doesn't
7171
os::cmd::try_until_failure "oc get secrets --token='${allescalatingpowerstoken}' -n default"
72-
os::cmd::expect_failure_and_text "oc get secrets --token='${allescalatingpowerstoken}' -n default" 'cannot list secrets in project'
72+
os::cmd::expect_failure_and_text "oc get secrets --token='${allescalatingpowerstoken}' -n default" 'cannot list secrets in the namespace'
7373
os::cmd::expect_success_and_text "oc get projects --token='${allescalatingpowerstoken}'" "${project}"
7474
os::cmd::expect_success_and_text "oc policy can-i --list --token='${allescalatingpowerstoken}' -n '${project}'" 'get.*pods'
7575

test/cmd/status.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ os::cmd::expect_success_and_text "oc login --server=${KUBERNETES_MASTER} --certi
4444
os::cmd::expect_success_and_text 'oc status' "You don't have any projects. You can try to create a new project, by running"
4545
os::cmd::expect_success_and_text 'oc status --all-namespaces' "Showing all projects on server"
4646
# make sure `oc status` does not re-use the "no projects" message from `oc login` if -n is specified
47-
os::cmd::expect_failure_and_text 'oc status -n forbidden' 'Error from server \(Forbidden\): User "test-user" cannot get project "forbidden"'
47+
os::cmd::expect_failure_and_text 'oc status -n forbidden' 'Error from server \(Forbidden\): User "test-user" cannot get projects in the namespace "forbidden"'
4848

4949
# create a new project
5050
os::cmd::expect_success "oc new-project project-bar --display-name='my project' --description='test project'"
5151
os::cmd::expect_success_and_text "oc project" 'Using project "project-bar"'
5252

5353
# make sure `oc status` does not use "no projects" message if there is a project created
5454
os::cmd::expect_success_and_text 'oc status' "In project my project \(project-bar\) on server"
55-
os::cmd::expect_failure_and_text 'oc status -n forbidden' 'Error from server \(Forbidden\): User "test-user" cannot get project "forbidden"'
55+
os::cmd::expect_failure_and_text 'oc status -n forbidden' 'Error from server \(Forbidden\): User "test-user" cannot get projects in the namespace "forbidden"'
5656

5757
# create a second project
5858
os::cmd::expect_success "oc new-project project-bar-2 --display-name='my project 2' --description='test project 2'"
@@ -62,7 +62,7 @@ os::cmd::expect_success_and_text "oc project" 'Using project "project-bar-2"'
6262
# message since `project-bar` still exists
6363
os::cmd::expect_success_and_text "oc delete project project-bar-2" 'project "project-bar-2" deleted'
6464
# the deletion is asynchronous and can take a while, so wait until we see the error
65-
os::cmd::try_until_text "oc status" 'Error from server \(Forbidden\): User "test-user" cannot get project "project-bar-2"'
65+
os::cmd::try_until_text "oc status" 'Error from server \(Forbidden\): User "test-user" cannot get projects in the namespace "project-bar-2"'
6666

6767
# delete "project-bar" and test that `oc status` still does not return the "no projects" message.
6868
# Although we are deleting the last remaining project, the current context's namespace is still set
@@ -71,7 +71,7 @@ os::cmd::try_until_text "oc status" 'Error from server \(Forbidden\): User "test
7171
os::cmd::expect_success "oc project project-bar"
7272
os::cmd::expect_success "oc delete project project-bar"
7373
# the deletion is asynchronous and can take a while, so wait until we see the error
74-
os::cmd::try_until_text "oc status" 'Error from server \(Forbidden\): User "test-user" cannot get project "project-bar"'
74+
os::cmd::try_until_text "oc status" 'Error from server \(Forbidden\): User "test-user" cannot get projects in the namespace "project-bar"'
7575
os::cmd::try_until_not_text "oc get projects" "project-bar"
7676
os::cmd::try_until_not_text "oc get projects" "project-bar-2"
7777
os::cmd::expect_success "oc logout"

test/integration/authorization_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1174,17 +1174,17 @@ func TestAuthorizationSubjectAccessReview(t *testing.T) {
11741174
localReview: askCanEdgarDeletePods,
11751175
kubeAuthInterface: haroldSARGetter,
11761176
kubeNamespace: "mallet-project",
1177-
err: `User "harold" cannot create localsubjectaccessreviews in project "mallet-project"`,
1178-
kubeErr: `User "harold" cannot create localsubjectaccessreviews.authorization.k8s.io in project "mallet-project"`,
1177+
err: `User "harold" cannot create localsubjectaccessreviews in the namespace "mallet-project"`,
1178+
kubeErr: `User "harold" cannot create localsubjectaccessreviews.authorization.k8s.io in the namespace "mallet-project"`,
11791179
}.run(t)
11801180
subjectAccessReviewTest{
11811181
description: "system:anonymous denied ability to run subject access review in project mallet-project",
11821182
localInterface: anonymousClient.LocalSubjectAccessReviews("mallet-project"),
11831183
localReview: askCanEdgarDeletePods,
11841184
kubeAuthInterface: anonymousSARGetter,
11851185
kubeNamespace: "mallet-project",
1186-
err: `User "system:anonymous" cannot create localsubjectaccessreviews in project "mallet-project"`,
1187-
kubeErr: `User "system:anonymous" cannot create localsubjectaccessreviews.authorization.k8s.io in project "mallet-project"`,
1186+
err: `User "system:anonymous" cannot create localsubjectaccessreviews in the namespace "mallet-project"`,
1187+
kubeErr: `User "system:anonymous" cannot create localsubjectaccessreviews.authorization.k8s.io in the namespace "mallet-project"`,
11881188
}.run(t)
11891189
// ensure message does not leak whether the namespace exists or not
11901190
subjectAccessReviewTest{
@@ -1193,17 +1193,17 @@ func TestAuthorizationSubjectAccessReview(t *testing.T) {
11931193
localReview: askCanEdgarDeletePods,
11941194
kubeAuthInterface: haroldSARGetter,
11951195
kubeNamespace: "nonexistent-project",
1196-
err: `User "harold" cannot create localsubjectaccessreviews in project "nonexistent-project"`,
1197-
kubeErr: `User "harold" cannot create localsubjectaccessreviews.authorization.k8s.io in project "nonexistent-project"`,
1196+
err: `User "harold" cannot create localsubjectaccessreviews in the namespace "nonexistent-project"`,
1197+
kubeErr: `User "harold" cannot create localsubjectaccessreviews.authorization.k8s.io in the namespace "nonexistent-project"`,
11981198
}.run(t)
11991199
subjectAccessReviewTest{
12001200
description: "system:anonymous denied ability to run subject access review in project nonexistent-project",
12011201
localInterface: anonymousClient.LocalSubjectAccessReviews("nonexistent-project"),
12021202
localReview: askCanEdgarDeletePods,
12031203
kubeAuthInterface: anonymousSARGetter,
12041204
kubeNamespace: "nonexistent-project",
1205-
err: `User "system:anonymous" cannot create localsubjectaccessreviews in project "nonexistent-project"`,
1206-
kubeErr: `User "system:anonymous" cannot create localsubjectaccessreviews.authorization.k8s.io in project "nonexistent-project"`,
1205+
err: `User "system:anonymous" cannot create localsubjectaccessreviews in the namespace "nonexistent-project"`,
1206+
kubeErr: `User "system:anonymous" cannot create localsubjectaccessreviews.authorization.k8s.io in the namespace "nonexistent-project"`,
12071207
}.run(t)
12081208

12091209
askCanHaroldUpdateProject := &authorizationapi.LocalSubjectAccessReview{

test/integration/bootstrap_policy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ func TestBootstrapPolicySelfSubjectAccessReviews(t *testing.T) {
112112
localReview: askCanClusterAdminsCreateProject,
113113
kubeAuthInterface: valerieKubeClient.Authorization(),
114114
kubeNamespace: "openshift",
115-
err: `User "valerie" cannot create localsubjectaccessreviews in project "openshift"`,
116-
kubeErr: `User "valerie" cannot create localsubjectaccessreviews.authorization.k8s.io in project "openshift"`,
115+
err: `User "valerie" cannot create localsubjectaccessreviews in the namespace "openshift"`,
116+
kubeErr: `User "valerie" cannot create localsubjectaccessreviews.authorization.k8s.io in the namespace "openshift"`,
117117
}.run(t)
118118

119119
}

test/integration/oauth_cert_fallback_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestOAuthCertFallback(t *testing.T) {
3535
certUser = "system:admin"
3636

3737
unauthorizedError = "the server has asked for the client to provide credentials (get users ~)"
38-
anonymousError = `User "system:anonymous" cannot get users at the cluster scope`
38+
anonymousError = `User "system:anonymous" cannot get users at the cluster scope.: "User \"system:anonymous\" cannot get users at the cluster scope" (get users ~)`
3939
)
4040

4141
// Build master config

0 commit comments

Comments
 (0)