Files
probo/pkg/accessreview/drivers/openrouter_test.go
Aurélien Sibiril a0d3806c21 Add four API-key access-review connectors
Add Pylon, OpenRouter, incident.io and Brevo as access-review connectors.
All are API-key, single-tenant providers (Pattern 3): the key identifies
one tenant, so there is no OAuth flow, picker UI, or bootstrap/helm
configuration.

- Pylon: Bearer token, GET /users; resolves each user's opaque role_id to
  a role name via GET /user-roles, with cursor pagination.
- OpenRouter: Bearer management key, GET /api/v1/organization/members. The
  endpoint requires an organization account -- a personal key authenticates
  but returns 404 -- so the connection probe rejects 404 on top of 401/403
  (doProbeRequest gained an opt-in extra-reject set) to surface a non-org
  key at connect time instead of mid-campaign.
- incident.io: Bearer token, GET /v2/users. Its OAuth is outbound-only, so
  the API key is the inbound path; live base_role/custom_roles take
  precedence over the deprecated role enum.
- Brevo: API key in the api-key header (Registration.APIKeyHeader), GET
  /v3/organization/invited/users. A live recording corrected the documented
  schema: is_owner is a JSON boolean (not a string) and an id field is
  present, so it is used as the stable ExternalID.

The OpenRouter and Brevo cassettes are anonymized live recordings; Pylon
and incident.io use hand-authored fixtures (no self-serve test tenant). The
shared three-valued active-status mapping is consolidated into
activeFromStatus in driver.go.

Each adds the enum value, migration, GraphQL binding, provider
Registration, a driver with a cassette-driven test, and a brand logo.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-06-24 22:22:51 +02:00

75 lines
2.9 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package drivers
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.probo.inc/probo/pkg/coredata"
)
func TestOpenRouterDriver(t *testing.T) {
t.Parallel()
rec := newRecorder(t, "testdata/openrouter", "OPENROUTER_API_KEY")
client := newVCRClient(rec, bearerAuth(os.Getenv("OPENROUTER_API_KEY")))
driver := NewOpenRouterDriver(client)
records, err := driver.ListAccounts(context.Background())
require.NoError(t, err)
require.Len(t, records, 1)
// Cassette recorded live against an OpenRouter organization (single admin
// member), then anonymized.
admin := records[0]
assert.Equal(t, "user_000000000000000000000admin", admin.ExternalID)
assert.Equal(t, "ada.admin@example.com", admin.Email)
assert.Equal(t, "Ada Admin", admin.FullName)
assert.Equal(t, []string{"Admin"}, admin.Roles)
assert.True(t, admin.IsAdmin)
assert.Equal(t, coredata.AccessReviewEntryAccountTypeUser, admin.AccountType)
// The members endpoint carries no account-status field, so Active stays nil.
assert.Nil(t, admin.Active)
}
func TestOpenRouterRoles(t *testing.T) {
t.Parallel()
assert.Equal(t, []string{"Admin"}, openRouterRoles("org:admin"))
assert.Equal(t, []string{"Member"}, openRouterRoles("org:member"))
// An unknown future role is preserved verbatim; an empty role yields none.
assert.Equal(t, []string{"org:billing"}, openRouterRoles("org:billing"))
assert.Equal(t, []string{}, openRouterRoles(""))
}
func TestOpenRouterFullName(t *testing.T) {
t.Parallel()
first, last := "Bob", "Member"
// first + last.
assert.Equal(t, "Bob Member", openRouterFullName(openRouterMember{FirstName: &first, LastName: &last}, "bob@example.com"))
// last_name null → first name alone.
assert.Equal(t, "Bob", openRouterFullName(openRouterMember{FirstName: &first}, "bob@example.com"))
// first_name null → last name alone.
assert.Equal(t, "Member", openRouterFullName(openRouterMember{LastName: &last}, "bob@example.com"))
// both null → email fallback.
assert.Equal(t, "carol@example.com", openRouterFullName(openRouterMember{}, "carol@example.com"))
}