Files
probo/pkg/accessreview/drivers/railway_test.go
Sacha Al Himdani 4c57d201a4 Make license declarations consistently MIT
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>
2026-07-13 16:21:14 +02:00

121 lines
4.3 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"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.probo.inc/probo/pkg/coredata"
)
func TestRailwayDriver(t *testing.T) {
t.Parallel()
rec := newRecorder(t, "testdata/railway", "RAILWAY_TOKEN")
client := newVCRClient(rec, bearerAuth(os.Getenv("RAILWAY_TOKEN")))
driver := NewRailwayDriver(client)
records, err := driver.ListAccounts(context.Background())
require.NoError(t, err)
require.Len(t, records, 2)
admin := records[0]
assert.Equal(t, "8f7e6d5c-4b3a-2910-8a7b-6c5d4e3f2a1b", admin.ExternalID)
assert.Equal(t, "ada@example.com", admin.Email)
assert.Equal(t, "Ada Lovelace", admin.FullName)
assert.Equal(t, []string{"Admin"}, admin.Roles)
assert.True(t, admin.IsAdmin)
assert.Equal(t, coredata.MFAStatusEnabled, admin.MFAStatus)
// Railway's WorkspaceMember exposes no status/active field.
assert.Nil(t, admin.Active)
assert.Equal(t, coredata.AccessReviewEntryAccountTypeUser, admin.AccountType)
member := records[1]
assert.Equal(t, "1b2c3d4e-5f6a-7b8c-9d0e-1f2a3b4c5d6e", member.ExternalID)
assert.Equal(t, "grace@example.com", member.Email)
assert.Equal(t, []string{"Member"}, member.Roles)
assert.False(t, member.IsAdmin)
assert.Equal(t, coredata.MFAStatusDisabled, member.MFAStatus)
assert.Nil(t, member.Active)
}
// TestRailwayRecords drives the cross-workspace aggregation directly (the
// cassette has a single workspace, so it cannot exercise dedup). A member who
// appears in two workspaces yields one record with unioned roles, IsAdmin true
// if any appearance is ADMIN, and MFA enabled if any appearance reports it; a
// member whose two-factor flag is null in every workspace stays Unknown.
func TestRailwayRecords(t *testing.T) {
t.Parallel()
enabled := true
disabled := false
me := &railwayMe{
Workspaces: []railwayWorkspace{
{
ID: "ws-a",
Name: "Alpha",
Members: []railwayMember{
{ID: "u-alice", Email: "alice@example.com", Name: "Alice", Role: "ADMIN", TwoFactorAuthEnabled: &enabled},
{ID: "u-bob", Email: "bob@example.com", Name: "Bob", Role: "MEMBER", TwoFactorAuthEnabled: &disabled},
{ID: "u-carol", Email: "carol@example.com", Name: "Carol", Role: "VIEWER"},
},
},
{
ID: "ws-b",
Name: "Beta",
Members: []railwayMember{
{ID: "u-alice", Email: "alice@example.com", Name: "Alice", Role: "MEMBER", TwoFactorAuthEnabled: &disabled},
{ID: "u-carol", Email: "carol@example.com", Name: "Carol", Role: "VIEWER"},
},
},
},
}
records := railwayRecords(me)
require.Len(t, records, 3)
byID := make(map[string]AccountRecord, len(records))
for _, r := range records {
byID[r.ExternalID] = r
}
alice := byID["u-alice"]
assert.Equal(t, []string{"Admin", "Member"}, alice.Roles)
assert.True(t, alice.IsAdmin)
assert.Equal(t, coredata.MFAStatusEnabled, alice.MFAStatus)
assert.Nil(t, alice.Active)
bob := byID["u-bob"]
assert.Equal(t, []string{"Member"}, bob.Roles)
assert.False(t, bob.IsAdmin)
assert.Equal(t, coredata.MFAStatusDisabled, bob.MFAStatus)
carol := byID["u-carol"]
assert.Equal(t, []string{"Viewer"}, carol.Roles)
assert.False(t, carol.IsAdmin)
assert.Equal(t, coredata.MFAStatusUnknown, carol.MFAStatus)
}