Skip to content

Commit c6e79e3

Browse files
committed
test: Add example configuration and tests for endpoint-level auth
**Configuration:** - Update config.yaml with endpoint-level auth example - Add basic auth credentials and public endpoint markers - Configure SQLite storage for testing **Tests:** - Add test for default auth level (global) - Add test for invalid auth level validation - Fix config test formatting This demonstrates the endpoint-level authentication feature where authentication is optional but filters visible data.
1 parent 1f1e7e9 commit c6e79e3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

config/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/TwiN/gatus/v5/config/tunneling"
5858
"github.com/TwiN/gatus/v5/config/tunneling/sshtunnel"
5959
"github.com/TwiN/gatus/v5/config/web"
60+
"github.com/TwiN/gatus/v5/security"
6061
"github.com/TwiN/gatus/v5/storage"
6162
"gopkg.in/yaml.v3"
6263
)
@@ -1864,8 +1865,8 @@ endpoints:
18641865
}
18651866
if config.Security.Basic.PasswordBcryptHashBase64Encoded != expectedPasswordHash {
18661867
t.Errorf("config.Security.Basic.PasswordBcryptHashBase64Encoded should've been %s, but was %s", expectedPasswordHash, config.Security.Basic.PasswordBcryptHashBase64Encoded)
1867-
}
1868-
}
1868+
}}
1869+
18691870

18701871
func TestParseAndValidateConfigBytesWithLiteralDollarSign(t *testing.T) {
18711872
os.Setenv("GATUS_TestParseAndValidateConfigBytesWithLiteralDollarSign", "whatever")

security/config_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ func TestConfig_ValidateAndSetDefaults(t *testing.T) {
1717
if c.ValidateAndSetDefaults() {
1818
t.Error("expected empty config to be valid")
1919
}
20+
if c.Level != authLevelGlobal {
21+
t.Errorf("Default level should be %s", authLevelGlobal)
22+
}
23+
}
24+
25+
func TestConfig_ValidateLevel(t *testing.T) {
26+
c := &Config{
27+
Basic: nil,
28+
OIDC: nil,
29+
Level: "WrongLevel",
30+
}
31+
valid := c.ValidateAndSetDefaults();
32+
if valid {
33+
t.Error("expected invalid level to mark config has invalid")
34+
}
2035
}
2136

2237
func TestConfig_ApplySecurityMiddleware(t *testing.T) {

0 commit comments

Comments
 (0)