Skip to content

Commit

Permalink
Improve string comparison for privileged_pods and smcp_logging tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 authored Oct 1, 2024
1 parent e0598e9 commit b131ea9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 16 additions & 7 deletions pkg/tests/ossm/privileged_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ spec:
app.InstallAndWaitReady(t, app.Httpbin(ns.Foo))

t.NewSubTest("Check sleep with explicitly defined SecurityContext with same uid/gid (1001)").Run(func(t TestHelper) {
runSecurityContextTest(t, 1001, 1001, "uid=1002(1002) gid=1002(1002) groups=1002(1002)")
runSecurityContextTest(t, 1001, 1001, "uid=1002", "gid=1002", "groups=1002")
})

t.NewSubTest("Check sleep with explicitly defined SecurityContext with root uid/gid").Run(func(t TestHelper) {
runSecurityContextTest(t, 0, 0, "uid=1(bin) gid=1(bin) groups=1(bin)")
runSecurityContextTest(t, 0, 0, "uid=1", "gid=1", "groups=1")
})
})
}

func runSecurityContextTest(t TestHelper, uid, gid int, expectedIDOutput string) {
func runSecurityContextTest(t TestHelper, uid, gid int, expectedUid, expectedGid, expectedGroups string) {
t.Cleanup(func() {
app.Uninstall(t, app.SleepSecurityContext(ns.Foo, uid, gid))
})
Expand All @@ -80,13 +80,22 @@ func runSecurityContextTest(t TestHelper, uid, gid int, expectedIDOutput string)
app.SleepSecurityContext(ns.Foo, uid, gid),
)

t.LogStepf("Verify that UID, GID and Groups were changed to: %s", expectedIDOutput)
t.LogStepf("Verify that UID, GID and Groups were changed to: %s, %s, %s", expectedUid, expectedGid, expectedGroups)
oc.Exec(t, pod.MatchingSelector("app=sleep", ns.Foo), "istio-proxy",
"id",
assert.OutputContains(
expectedIDOutput,
"UID, GID and Groups were changed",
"UID, GID and Groups were not changed"))
expectedUid,
"UID was changed",
"UID was not changed"),
assert.OutputContains(
expectedGid,
"GID was changed",
"GID was not changed"),
assert.OutputContains(
expectedGroups,
"Groups were changed",
"Groups were not changed"),
)

t.LogStep("Verify that a request from sleep to httpbin returns 200")
app.AssertSleepPodRequestSuccess(t, ns.Foo, "http://httpbin:8000/ip")
Expand Down
11 changes: 9 additions & 2 deletions pkg/tests/ossm/smcp_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ func TestLogging(t *testing.T) {
t.LogStep("Try to patch SMCP with unsupported log levels (trace, critical), patch should fail")
shell.Execute(t,
fmt.Sprintf("oc patch smcp/%s -n %s --type merge --patch '%s' || true", smcpName, meshNamespace, errorLoggingComponentLevelsSMCP),
assert.OutputContains(`Error from server (BadRequest): admission webhook "smcp.validation.maistra.io" denied the request: [istiod doesn't support 'trace' log level, istiod doesn't support 'critical' log level]`,
assert.OutputContains(`Error from server (BadRequest): admission webhook "smcp.validation.maistra.io" denied the request:`,
"Patch failed as expected due to unsupported log levels",
"Patch succeeded unexpectedly, unsupported log levels were not rejected"))
"Patch succeeded unexpectedly, unsupported log levels were not rejected"),
assert.OutputContains(`istiod doesn't support 'trace' log level`,
"Patch failed as expected due to unsupported log levels",
"Patch succeeded unexpectedly, unsupported log levels were not rejected"),
assert.OutputContains(`istiod doesn't support 'critical' log level`,
"Patch failed as expected due to unsupported log levels",
"Patch succeeded unexpectedly, unsupported log levels were not rejected"),
)

t.LogStep("Wait SMCP ready")
oc.WaitSMCPReady(t, meshNamespace, smcpName)
Expand Down

0 comments on commit b131ea9

Please sign in to comment.