{"record":{"id":"346941d515ed1a26","repo":"juanfont/headscale","slug":"running-mock-oidc-server-w","errorCode":null,"errorMessage":"running mock OIDC server: %w","messagePattern":"running mock OIDC server: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/headscale/cli/mockoidc.go","lineNumber":42,"sourceCode":"\terrMockOidcUsersNotDefined        = errors.New(\"MOCKOIDC_USERS not defined\")\n)\n\nconst refreshTTL = 60 * time.Minute\n\nvar accessTTL = 2 * time.Minute\n\nfunc init() {\n\trootCmd.AddCommand(mockOidcCmd)\n}\n\nvar mockOidcCmd = &cobra.Command{\n\tUse:   \"mockoidc\",\n\tShort: \"Runs a mock OIDC server for testing\",\n\tLong:  \"This internal command runs a OpenID Connect for testing purposes\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\terr := mockOIDC()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"running mock OIDC server: %w\", err)\n\t\t}\n\n\t\treturn nil\n\t},\n}\n\nfunc mockOIDC() error {\n\tclientID := os.Getenv(\"MOCKOIDC_CLIENT_ID\")\n\tif clientID == \"\" {\n\t\treturn errMockOidcClientIDNotDefined\n\t}\n\n\tclientSecret := os.Getenv(\"MOCKOIDC_CLIENT_SECRET\")\n\tif clientSecret == \"\" {\n\t\treturn errMockOidcClientSecretNotDefined\n\t}\n\n\taddrStr := os.Getenv(\"MOCKOIDC_ADDR\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/headscale/cli/mockoidc.go#L24-L60","documentation":"Top-level wrap around mockOIDC() for the internal 'headscale mockoidc' command: the mock OpenID Connect server used in integration testing failed to start or run. The wrapped error identifies the stage — missing env config (client id/issuer), bad listening address, or a runtime failure of the embedded OIDC provider.","triggerScenarios":"Running 'headscale mockoidc' without the required environment variables (e.g., MOCKOIDC_CLIENT_ID unset yields errMockOidcClientIDNotDefined), with an invalid issuer URL, or when its listen port is already taken.","commonSituations":"Integration test harness misconfiguration (env vars not exported); port conflicts when a previous mock server did not shut down; running the command outside the test container where /etc/headscale networking assumptions do not hold.","solutions":["Set the required env vars — at minimum MOCKOIDC_CLIENT_ID (check mockoidc.go for the full list: issuer, addr, client secret)","Free the configured listen port (kill stale mockoidc processes)","Run it inside the integration environment that normally configures it, rather than ad hoc"],"exampleFix":"# before\nheadscale mockoidc\n\n# after\nexport MOCKOIDC_CLIENT_ID=test-client\nheadscale mockoidc","handlingStrategy":"validation","validationCode":"for _, k := range []string{\"MOCKOIDC_CLIENT_ID\" /* + issuer/addr per mockoidc.go */} {\n\tif os.Getenv(k) == \"\" {\n\t\tlog.Fatalf(\"required env %s not set\", k)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := mockOIDC(); err != nil {\n\tlog.Fatalf(\"mock oidc failed: %v\", err) // fail the harness fast, surface wrapped cause\n}","preventionTips":["Export all MOCKOIDC_* vars in the integration harness before launch","Allocate a dedicated port for the mock server to avoid conflicts","Run the mock server only within the test environment that provisions it"],"tags":["oidc","testing","environment","server","go"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}