package oauth import ( "context" "errors" "net/http" "testing" ) func TestInteractiveFlowWithCallback_ErrorOnBadCallback(t *testing.T) { ctx := context.Background() baseURL := "http://localhost:8080" handle := "alice.bsky.social" scopes := []string{"atproto"} // Test with failing callback registration registerCallback := func(handler http.HandlerFunc) error { return errors.New("callback registration failed") } displayAuthURL := func(url string) error { return nil } result, err := InteractiveFlowWithCallback( ctx, baseURL, handle, scopes, "AT Container Registry", registerCallback, displayAuthURL, ) if err == nil { t.Error("Expected error when callback registration fails") } if result != nil { t.Error("Expected nil result on error") } } func TestInteractiveFlowWithCallback_NilScopes(t *testing.T) { // Test that nil scopes doesn't panic // This is a quick validation test - full flow test requires // mock OAuth server which will be added in comprehensive implementation ctx := context.Background() baseURL := "http://localhost:8080" handle := "alice.bsky.social" callbackRegistered := false registerCallback := func(handler http.HandlerFunc) error { callbackRegistered = true // Simulate successful registration but don't actually call the handler // (full flow would require OAuth server mock) return nil } displayAuthURL := func(url string) error { // In real flow, this would display URL to user return nil } // This will fail at the auth flow stage (no real PDS), but that's expected // We're just verifying it doesn't panic with nil scopes _, err := InteractiveFlowWithCallback( ctx, baseURL, handle, nil, // nil scopes should use defaults "AT Container Registry", registerCallback, displayAuthURL, ) // Error is expected since we don't have a real OAuth flow // but we verified no panic if err == nil { t.Log("Unexpected success - likely callback never triggered") } if !callbackRegistered { t.Error("Expected callback to be registered") } } // Note: Full interactive flow tests with mock OAuth server will be added // in comprehensive implementation phase