Skip to content

Commit

Permalink
test: ensure chmod calls run on test failure for authn errors test
Browse files Browse the repository at this point in the history
Signed-off-by: evanebb <git@evanus.nl>
  • Loading branch information
evanebb committed Mar 5, 2025
1 parent 14a1bec commit acb07af
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions pkg/api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,11 @@ func TestAuthnErrors(t *testing.T) {
err := os.WriteFile(tmpFile, []byte("test"), 0o000)
So(err, ShouldBeNil)

defer func() {
err := os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
}()

conf.HTTP.Auth.LDAP = (&config.LDAPConfig{
Insecure: true,
Address: LDAPAddress,
Expand All @@ -2328,9 +2333,6 @@ func TestAuthnErrors(t *testing.T) {
So(func() {
api.AuthHandler(ctlr)
}, ShouldPanic)

err = os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
})

Convey("ldap CA certs is empty", t, func() {
Expand Down Expand Up @@ -2391,6 +2393,11 @@ func TestAuthnErrors(t *testing.T) {
err := os.WriteFile(tmpFile, []byte("test"), 0o000)
So(err, ShouldBeNil)

defer func() {
err := os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
}()

conf.HTTP.Auth.HTPasswd = config.AuthHTPasswd{
Path: tmpFile,
}
Expand All @@ -2400,9 +2407,6 @@ func TestAuthnErrors(t *testing.T) {
So(func() {
api.AuthHandler(ctlr)
}, ShouldPanic)

err = os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
})

Convey("Bearer auth invalid PEM data", t, func() {
Expand All @@ -2415,6 +2419,11 @@ func TestAuthnErrors(t *testing.T) {
err := os.WriteFile(tmpFile, []byte("invalid"), 0o000)
So(err, ShouldBeNil)

defer func() {
err := os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
}()

conf.HTTP.Auth.Bearer = &config.BearerConfig{
Realm: "realm",
Service: "service",
Expand All @@ -2426,9 +2435,6 @@ func TestAuthnErrors(t *testing.T) {
So(func() {
api.AuthHandler(ctlr)
}, ShouldPanic)

err = os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
})

Convey("Bearer auth invalid certificate", t, func() {
Expand All @@ -2442,6 +2448,11 @@ func TestAuthnErrors(t *testing.T) {
err := os.WriteFile(tmpFile, []byte("-----BEGIN CERTIFICATE-----\naW52YWxpZA==\n-----END CERTIFICATE-----"), 0o000)
So(err, ShouldBeNil)

defer func() {
err := os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
}()

conf.HTTP.Auth.Bearer = &config.BearerConfig{
Realm: "realm",
Service: "service",
Expand All @@ -2453,9 +2464,6 @@ func TestAuthnErrors(t *testing.T) {
So(func() {
api.AuthHandler(ctlr)
}, ShouldPanic)

err = os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
})

Convey("NewRelyingPartyGithub fail", t, func() {
Expand All @@ -2468,16 +2476,18 @@ func TestAuthnErrors(t *testing.T) {
err := os.WriteFile(tmpFile, []byte("test"), 0o000)
So(err, ShouldBeNil)

defer func() {
err := os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
}()

conf.HTTP.Auth.HTPasswd = config.AuthHTPasswd{
Path: tmpFile,
}

So(func() {
api.NewRelyingPartyGithub(conf, "prov", nil, nil, log.NewLogger("debug", ""))
}, ShouldPanic)

err = os.Chmod(tmpFile, 0o644)
So(err, ShouldBeNil)
})
}

Expand Down

0 comments on commit acb07af

Please sign in to comment.