MCPcopy Create free account
hub / github.com/brimdata/super / TestAuthIdentity

Function TestAuthIdentity

service/auth_test.go:35–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestAuthIdentity(t *testing.T) {
36 authConfig := testAuthConfig()
37 core, conn := newCoreWithConfig(t, service.Config{
38 Auth: authConfig,
39 })
40 _, err := conn.Query(t.Context(), srcfiles.Plain("from [pools]"))
41 require.Error(t, err)
42 require.Equal(t, 1.0, promCounterValue(core.Registry(), "request_errors_unauthorized_total"))
43
44 var poolErr *client.ErrorResponse
45 require.True(t, errors.As(err, &poolErr))
46 require.Equal(t, http.StatusUnauthorized, poolErr.StatusCode)
47
48 var identErr *client.ErrorResponse
49 _, err = conn.AuthIdentity(t.Context())
50 require.Error(t, err)
51 require.True(t, errors.As(err, &identErr))
52 require.Equal(t, http.StatusUnauthorized, identErr.StatusCode)
53
54 token := genToken(t, "test_tenant_id", "test_user_id")
55 conn.SetAuthToken(token)
56 res := conn.TestAuthIdentity()
57 require.Equal(t, api.AuthIdentityResponse{
58 TenantID: "test_tenant_id",
59 UserID: "test_user_id",
60 }, res)
61
62 _, err = conn.Query(t.Context(), srcfiles.Plain("from :pools"))
63 require.NoError(t, err)
64}
65
66func TestAuthMethodGet(t *testing.T) {
67 t.Run("none", func(t *testing.T) {

Callers

nothing calls this directly

Calls 13

PlainFunction · 0.92
testAuthConfigFunction · 0.85
newCoreWithConfigFunction · 0.85
promCounterValueFunction · 0.85
ContextMethod · 0.80
RegistryMethod · 0.80
AuthIdentityMethod · 0.80
SetAuthTokenMethod · 0.80
TestAuthIdentityMethod · 0.80
genTokenFunction · 0.70
QueryMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected