Skip to content

Commit 759c589

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 d0b30eb commit 759c589

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
@@ -56,6 +56,7 @@ import (
5656
"github.com/TwiN/gatus/v5/config/tunneling"
5757
"github.com/TwiN/gatus/v5/config/tunneling/sshtunnel"
5858
"github.com/TwiN/gatus/v5/config/web"
59+
"github.com/TwiN/gatus/v5/security"
5960
"github.com/TwiN/gatus/v5/storage"
6061
"gopkg.in/yaml.v3"
6162
)
@@ -1814,8 +1815,8 @@ endpoints:
18141815
}
18151816
if config.Security.Basic.PasswordBcryptHashBase64Encoded != expectedPasswordHash {
18161817
t.Errorf("config.Security.Basic.PasswordBcryptHashBase64Encoded should've been %s, but was %s", expectedPasswordHash, config.Security.Basic.PasswordBcryptHashBase64Encoded)
1817-
}
1818-
}
1818+
}}
1819+
18191820

18201821
func TestParseAndValidateConfigBytesWithLiteralDollarSign(t *testing.T) {
18211822
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)