gofr-dev/gofr · warning
errMessage (dynamic credential validation error)
Error message
errMessage (dynamic credential validation error)
What it means
In the mock OAuth server (mock_oauth_server.go:57), validateCredentials returns an error message and HTTP status; when credentials are invalid the handler responds with http.Error(w, errMessage, statusCode). The exact body text is dynamic — it comes from the server's credential validator (e.g. "invalid client credentials"), so this entry represents whatever message your validateCredentials implementation produced.
Source
Thrown at pkg/gofr/service/mock_oauth_server.go:57
testURL: "/test",
audienceClaim: config.EndpointParams.Get("aud"),
}
server.clientID = config.ClientID
server.clientSecret = config.ClientSecret
privateKey, err := rsa.GenerateKey(rand.Reader, privateKeyBits)
require.NoError(t, err, "failed to generate private key, aborting")
server.privateKey = privateKey
mux := http.NewServeMux()
mux.HandleFunc(server.tokenURL, func(w http.ResponseWriter, r *http.Request) {
errMessage, statusCode := server.validateCredentials(r)
if statusCode != http.StatusOK {
http.Error(w, errMessage, statusCode)
return
}
accessToken, err := server.generateToken(getClaims(r))
if err != nil {
http.Error(w, "Unable to generate token", http.StatusInternalServerError)
return
}
// Prepare the JSON response
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Pragma", "no-cache")
tokenResponse := map[string]any{
"access_token": accessToken,
"token_type": "Bearer",
"expires_in": 3600, // Expires in 1 hourView on GitHub (pinned to 187eb24962)
Solutions
- Use the client credentials returned by the mock server's setup (oAuthConfigForTests) in the client under test.
- Inspect validateCredentials in your mock server setup to see which credential fields it compares and align the test request.
- Regenerate test credentials if generateRandomString output was persisted/staled across runs.
- Log the request's credentials in the mock to diff expected vs actual.
Defensive patterns
Strategy: validation
Validate before calling
// client side, before requesting a token
if clientID == "" || clientSecret == "" {
return errors.New("missing client credentials for mock OAuth server")
} Try / catch
resp, err := client.Token(ctx, creds)
if err != nil {
log.Printf("mock token endpoint said: %s", readBody(resp)) // dynamic validator message
return fmt.Errorf("credential rejected by mock server: %w", err)
} Prevention
- Source test credentials from the same helper (oAuthConfigForTests) that configures the mock server.
- Never hardcode credentials that may drift from the mock's validateCredentials.
- Assert the token endpoint returns 200 in test setup before running dependent tests.
- Keep validateCredentials and test fixtures in the same package so they change together.
When it happens
Trigger: A test client POSTs to the mock server's token URL with a client ID/secret (or other credentials) that fail the server's validateCredentials check; the response carries that validator's message with a non-200 status.
Common situations: Using oAuthConfigForTests-generated credentials against a differently configured mock server; stale credentials cached in test fixtures; pointing a real client at the mock token endpoint with production credentials.
Related errors
- Unable to generate token
- api keys list is empty
- container is nil
- validate func is empty
- user list is empty
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/d8d92e7261338ccb.
Report an issue: GitHub.