mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-27 12:05:26 +00:00
Linting and updating tests
This commit is contained in:
parent
7bf2a91dd0
commit
daa75da277
2
app.go
2
app.go
@ -171,7 +171,7 @@ func LookupTLSClientAuthMode(mode string) (tls.ClientAuthType, bool) {
|
|||||||
// Client cert is _required and verified_.
|
// Client cert is _required and verified_.
|
||||||
return tls.RequireAndVerifyClientCert, true
|
return tls.RequireAndVerifyClientCert, true
|
||||||
default:
|
default:
|
||||||
// Return the default when an unknown value is supplied.
|
// Return the default when an unknown value is supplied.
|
||||||
return tls.RequireAnyClientCert, false
|
return tls.RequireAnyClientCert, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
app_test.go
10
app_test.go
@ -69,9 +69,8 @@ func (s *Suite) ResetDB(c *check.C) {
|
|||||||
// Enusre an error is returned when an invalid auth mode
|
// Enusre an error is returned when an invalid auth mode
|
||||||
// is supplied.
|
// is supplied.
|
||||||
func (s *Suite) TestInvalidClientAuthMode(c *check.C) {
|
func (s *Suite) TestInvalidClientAuthMode(c *check.C) {
|
||||||
app.cfg.TLSClientAuthMode = "invalid"
|
_, isValid := LookupTLSClientAuthMode("invalid")
|
||||||
_, err := app.GetClientAuthMode()
|
c.Assert(isValid, check.Equals, false)
|
||||||
c.Assert(err, check.NotNil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that all client auth modes return a nil error.
|
// Ensure that all client auth modes return a nil error.
|
||||||
@ -79,8 +78,7 @@ func (s *Suite) TestAuthModes(c *check.C) {
|
|||||||
modes := []string{"disabled", "relaxed", "enforced"}
|
modes := []string{"disabled", "relaxed", "enforced"}
|
||||||
|
|
||||||
for _, v := range modes {
|
for _, v := range modes {
|
||||||
app.cfg.TLSClientAuthMode = v
|
_, isValid := LookupTLSClientAuthMode(v)
|
||||||
_, err := app.GetClientAuthMode()
|
c.Assert(isValid, check.Equals, true)
|
||||||
c.Assert(err, check.IsNil)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfig(path string) error {
|
func LoadConfig(path string) error {
|
||||||
|
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
if path == "" {
|
if path == "" {
|
||||||
viper.AddConfigPath("/etc/headscale/")
|
viper.AddConfigPath("/etc/headscale/")
|
||||||
@ -98,12 +97,12 @@ func LoadConfig(path string) error {
|
|||||||
_, authModeValid := headscale.LookupTLSClientAuthMode(viper.GetString("tls_client_auth_mode"))
|
_, authModeValid := headscale.LookupTLSClientAuthMode(viper.GetString("tls_client_auth_mode"))
|
||||||
|
|
||||||
if !authModeValid {
|
if !authModeValid {
|
||||||
errorText += fmt.Sprintf(
|
errorText += fmt.Sprintf(
|
||||||
"Invalid tls_client_auth_mode supplied: %s. Accepted values: %s, %s, %s.",
|
"Invalid tls_client_auth_mode supplied: %s. Accepted values: %s, %s, %s.",
|
||||||
viper.GetString("tls_client_auth_mode"),
|
viper.GetString("tls_client_auth_mode"),
|
||||||
headscale.DisabledClientAuth,
|
headscale.DisabledClientAuth,
|
||||||
headscale.RelaxedClientAuth,
|
headscale.RelaxedClientAuth,
|
||||||
headscale.EnforcedClientAuth)
|
headscale.EnforcedClientAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if errorText != "" {
|
if errorText != "" {
|
||||||
@ -295,7 +294,9 @@ func getHeadscaleConfig() headscale.Config {
|
|||||||
Msgf("'ip_prefixes' not configured, falling back to default: %v", prefixes)
|
Msgf("'ip_prefixes' not configured, falling back to default: %v", prefixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsClientAuthMode, _ := headscale.LookupTLSClientAuthMode(viper.GetString("tls_client_auth_mode"))
|
tlsClientAuthMode, _ := headscale.LookupTLSClientAuthMode(
|
||||||
|
viper.GetString("tls_client_auth_mode"),
|
||||||
|
)
|
||||||
|
|
||||||
return headscale.Config{
|
return headscale.Config{
|
||||||
ServerURL: viper.GetString("server_url"),
|
ServerURL: viper.GetString("server_url"),
|
||||||
|
Loading…
Reference in New Issue
Block a user