Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Font committed Sep 20, 2022
1 parent 7a171cf commit 083d2a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions cmd/headscale/cli/mockoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (
"github.com/spf13/cobra"
)

const (
errMockOidcClientIDNotDefined = Error("MOCKOIDC_CLIENT_ID not defined")
errMockOidcClientSecretNotDefined = Error("MOCKOIDC_CLIENT_SECRET not defined")
errMockOidcPortNotDefined = Error("MOCKOIDC_PORT not defined")
accessTTL = 10 * time.Minute
refreshTTL = 60 * time.Minute
)

func init() {
rootCmd.AddCommand(mockOidcCmd)
}
Expand All @@ -32,15 +40,15 @@ var mockOidcCmd = &cobra.Command{
func mockOIDC() error {
clientID := os.Getenv("MOCKOIDC_CLIENT_ID")
if clientID == "" {
return fmt.Errorf("MOCKOIDC_CLIENT_ID not set")
return errMockOidcClientIDNotDefined
}
clientSecret := os.Getenv("MOCKOIDC_CLIENT_SECRET")
if clientSecret == "" {
return fmt.Errorf("MOCKOIDC_CLIENT_SECRET not set")
return errMockOidcClientSecretNotDefined
}
portStr := os.Getenv("MOCKOIDC_PORT")
if portStr == "" {
return fmt.Errorf("MOCKOIDC_PORT not set")
return errMockOidcPortNotDefined
}

port, err := strconv.Atoi(portStr)
Expand All @@ -53,13 +61,16 @@ func mockOIDC() error {
return err
}

ln, err := net.Listen("tcp", fmt.Sprintf("mockoidc:%d", port))
listener, err := net.Listen("tcp", fmt.Sprintf("mockoidc:%d", port))
if err != nil {
return err
}

mock.Start(ln, nil)
log.Info().Msgf("Mock OIDC server listening on %s", ln.Addr().String())
err = mock.Start(listener, nil)
if err != nil {
return err
}
log.Info().Msgf("Mock OIDC server listening on %s", listener.Addr().String())
log.Info().Msgf("Issuer: %s", mock.Issuer())
c := make(chan struct{})
<-c
Expand All @@ -76,8 +87,8 @@ func getMockOIDC(clientID string, clientSecret string) (*mockoidc.MockOIDC, erro
mock := mockoidc.MockOIDC{
ClientID: clientID,
ClientSecret: clientSecret,
AccessTTL: time.Duration(10) * time.Minute,
RefreshTTL: time.Duration(60) * time.Minute,
AccessTTL: accessTTL,
RefreshTTL: refreshTTL,
CodeChallengeMethodsSupported: []string{"plain", "S256"},
Keypair: keypair,
SessionStore: mockoidc.NewSessionStore(),
Expand Down
2 changes: 1 addition & 1 deletion integration_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ oidc:
client := &http.Client{Transport: insecureTransport}
resp, err := client.Get(url)
if err != nil {
fmt.Printf("headscale for embedded OIDC tests is not ready: %s\n", err)
log.Printf("headscale for embedded OIDC tests is not ready: %s\n", err)
return err
}

Expand Down

0 comments on commit 083d2a8

Please sign in to comment.