cli/pkg/cmd/attestation/auth/host_test.go
Fredrik Skogman 1b59ec8ad0
This commit introduces tenancy aware attestation policy building.
This is done by inspecting the current hostname to determine if
tenancy is enabled.

The attestation commands also accepts a --hostname parameter, that
is used to pick the current host, similar to how the GH_HOST variable
can be used.

Signed-off-by: Fredrik Skogman <kommendorkapten@github.com>
2024-09-11 10:49:17 +02:00

52 lines
943 B
Go

package auth
import (
"testing"
ghauth "github.com/cli/go-gh/v2/pkg/auth"
"github.com/stretchr/testify/require"
)
func TestIsHostSupported(t *testing.T) {
testcases := []struct {
name string
expectedErr bool
host string
}{
{
name: "Default github.com host",
expectedErr: false,
host: "github.com",
},
{
name: "Localhost",
expectedErr: false,
host: "github.localhost",
},
{
name: "No host set",
expectedErr: false,
host: "",
},
{
name: "GHE tenant host",
expectedErr: false,
host: "some-tenant.ghe.com",
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("GH_HOST", tc.host)
host, _ := ghauth.DefaultHost()
err := IsHostSupported(host)
if tc.expectedErr {
require.ErrorIs(t, err, ErrUnsupportedHost)
} else {
require.NoError(t, err)
}
})
}
}