MCPcopy Create free account
hub / github.com/cloudbase/garm / ImpersonateAdminContext

Function ImpersonateAdminContext

internal/testing/testing.go:42–62  ·  view source on GitHub ↗
(ctx context.Context, db common.Store, s *testing.T)

Source from the content-addressed store, hash-verified

40var encryptionPassphrase = "bocyasicgatEtenOubwonIbsudNutDom"
41
42func ImpersonateAdminContext(ctx context.Context, db common.Store, s *testing.T) context.Context {
43 adminUser, err := db.GetAdminUser(ctx)
44 if err != nil {
45 if !errors.Is(err, runnerErrors.ErrNotFound) {
46 s.Fatalf("failed to get admin user: %v", err)
47 }
48 newUserParams := params.NewUserParams{
49 Email: "admin@localhost",
50 Username: "admin",
51 Password: "superSecretAdminPassword@123",
52 IsAdmin: true,
53 Enabled: true,
54 }
55 adminUser, err = db.CreateUser(ctx, newUserParams)
56 if err != nil {
57 s.Fatalf("failed to create admin user: %v", err)
58 }
59 }
60 ctx = auth.PopulateContext(ctx, adminUser, nil)
61 return ctx
62}
63
64func CreateGARMTestUser(ctx context.Context, username string, db common.Store, s *testing.T) params.User {
65 newUserParams := params.NewUserParams{

Callers

nothing calls this directly

Calls 3

PopulateContextFunction · 0.92
GetAdminUserMethod · 0.65
CreateUserMethod · 0.65

Tested by

no test coverage detected