The source headers, LICENSE files, and license metadata had drifted apart. Align the entire project to MIT: - Convert every source-file header to the MIT text across all comment styles (Go, TS, TSX, JS, MJS, SQL, CSS, GraphQL, shell), including SPDX-License-Identifier tags - Set the root and cookie-banner LICENSE files to the MIT text with a "MIT License" title line - Switch the package.json license fields, Docker image label, and cookie-banner README to MIT - Update docs and the genmodels header generator accordingly - Normalize copyright lines to a single format (Copyright (c) <year(s)> Probo Inc <hello@probo.com>.): unify the hello@getprobo.com and hello@probo.inc emails to hello@probo.com and the comma-separated years to a hyphenated range Genuine third-party references are intentionally left untouched: the Lucide icon attributions (Lucide is ISC) and the trivy dependency license allowlist. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
136 lines
4.7 KiB
Go
136 lines
4.7 KiB
Go
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
package drivers
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
)
|
|
|
|
func TestNeonDriverListAccounts(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
rec := newRecorder(t, "testdata/neon", "NEON_API_KEY")
|
|
client := newVCRClient(rec, bearerAuth(os.Getenv("NEON_API_KEY")))
|
|
|
|
orgID := os.Getenv("NEON_ORG_ID")
|
|
if orgID == "" {
|
|
orgID = "org-cool-breeze-12345678"
|
|
}
|
|
|
|
driver := NewNeonDriver(client, orgID)
|
|
records, err := driver.ListAccounts(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
// Four members across two pages in the cassette; the fourth has no
|
|
// email and is dropped.
|
|
require.Len(t, records, 3)
|
|
|
|
// Admin with MFA enabled and no deactivated_at. Neon exposes no
|
|
// display name on the members endpoint, so FullName is the email;
|
|
// ExternalID is the stable account UUID (member.user_id).
|
|
assert.Equal(t, "jane.doe@example.com", records[0].Email)
|
|
assert.Equal(t, "jane.doe@example.com", records[0].FullName)
|
|
assert.Equal(t, []string{"Admin"}, records[0].Roles)
|
|
assert.True(t, records[0].IsAdmin)
|
|
assert.Equal(t, coredata.MFAStatusEnabled, records[0].MFAStatus)
|
|
assert.Equal(t, "bbbbbbbb-1111-2222-3333-000000000001", records[0].ExternalID)
|
|
require.NotNil(t, records[0].Active)
|
|
assert.True(t, *records[0].Active)
|
|
require.NotNil(t, records[0].CreatedAt)
|
|
assert.Nil(t, records[0].LastLogin)
|
|
|
|
// Deactivated member with MFA disabled.
|
|
assert.Equal(t, "john.smith@example.com", records[1].Email)
|
|
assert.Equal(t, []string{"Member"}, records[1].Roles)
|
|
assert.False(t, records[1].IsAdmin)
|
|
assert.Equal(t, coredata.MFAStatusDisabled, records[1].MFAStatus)
|
|
assert.Equal(t, "bbbbbbbb-1111-2222-3333-000000000002", records[1].ExternalID)
|
|
require.NotNil(t, records[1].Active)
|
|
assert.False(t, *records[1].Active)
|
|
|
|
// Second page: editor with has_mfa omitted (Unknown) and an empty
|
|
// user_id falling back to the membership ID.
|
|
assert.Equal(t, "erin.lee@example.com", records[2].Email)
|
|
assert.Equal(t, []string{"Editor"}, records[2].Roles)
|
|
assert.False(t, records[2].IsAdmin)
|
|
assert.Equal(t, coredata.MFAStatusUnknown, records[2].MFAStatus)
|
|
assert.Equal(t, "aaaaaaaa-1111-2222-3333-000000000003", records[2].ExternalID)
|
|
require.NotNil(t, records[2].Active)
|
|
assert.True(t, *records[2].Active)
|
|
}
|
|
|
|
func TestNeonDriverListAccountsError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
client := &http.Client{
|
|
Transport: roundTripFunc(
|
|
func(req *http.Request) (*http.Response, error) {
|
|
return &http.Response{
|
|
StatusCode: http.StatusUnauthorized,
|
|
Body: io.NopCloser(strings.NewReader(`{"error":"unauthorized"}`)),
|
|
Header: make(http.Header),
|
|
}, nil
|
|
},
|
|
),
|
|
}
|
|
|
|
driver := NewNeonDriver(client, "org-cool-breeze-12345678")
|
|
_, err := driver.ListAccounts(context.Background())
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "unexpected status 401")
|
|
}
|
|
|
|
func TestNeonRoles(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
|
in string
|
|
want []string
|
|
isAdmin bool
|
|
}{
|
|
{in: "admin", want: []string{"Admin"}, isAdmin: true},
|
|
{in: "member", want: []string{"Member"}, isAdmin: false},
|
|
{in: "editor", want: []string{"Editor"}, isAdmin: false},
|
|
{in: "viewer", want: []string{"Viewer"}, isAdmin: false},
|
|
{in: "collaborator", want: []string{"Collaborator"}, isAdmin: false},
|
|
{in: "future_role", want: []string{"future_role"}, isAdmin: false},
|
|
{in: "", want: []string{}, isAdmin: false},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.in, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.Equal(t, c.want, neonRoles(c.in))
|
|
assert.Equal(t, c.isAdmin, neonIsAdmin(c.in))
|
|
})
|
|
}
|
|
}
|