-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
with_service_account_fail_test.go
74 lines (62 loc) · 2.18 KB
/
with_service_account_fail_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gitlab_test
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/vault/sdk/logical"
"github.com/stretchr/testify/require"
gitlab "github.com/ilijamt/vault-plugin-secrets-gitlab"
)
func TestWithServiceAccountUserFail(t *testing.T) {
for _, typ := range []gitlab.Type{
gitlab.TypeSaaS,
gitlab.TypeDedicated,
} {
t.Run(typ.String(), func(t *testing.T) {
httpClient, _ := getClient(t)
ctx := gitlab.HttpClientNewContext(context.Background(), httpClient)
b, l, events, err := getBackendWithEvents(ctx)
require.NoError(t, err)
resp, err := b.HandleRequest(ctx, &logical.Request{
Operation: logical.UpdateOperation,
Path: fmt.Sprintf("%s/%s", gitlab.PathConfigStorage, gitlab.DefaultConfigName), Storage: l,
Data: map[string]any{
"token": gitlabServiceAccountToken,
"base_url": gitlabServiceAccountUrl,
"auto_rotate_token": true,
"auto_rotate_before": "24h",
"type": typ.String(),
},
})
require.NoError(t, err)
require.NotNil(t, resp)
require.NoError(t, resp.Error())
require.NotEmpty(t, events)
require.NotNil(t, b.GetClient(gitlab.DefaultConfigName))
var gClient = b.GetClient(gitlab.DefaultConfigName).GitlabClient(ctx)
require.NotNil(t, gClient)
usr, _, err := gClient.Users.CreateServiceAccountUser()
require.NoError(t, err)
require.NotNil(t, usr)
resp, err = b.HandleRequest(ctx, &logical.Request{
Operation: logical.CreateOperation,
Path: fmt.Sprintf("%s/user-service-account", gitlab.PathRoleStorage), Storage: l,
Data: map[string]any{
"path": usr.Username,
"name": fmt.Sprintf(`user-service-account-%s`, usr.Username),
"token_type": gitlab.TokenTypeUserServiceAccount.String(),
"ttl": gitlab.DefaultAccessTokenMinTTL,
"scopes": gitlab.ValidUserServiceAccountTokenScopes,
"gitlab_revokes_token": false,
},
})
require.Error(t, err)
require.NotNil(t, resp)
require.Error(t, resp.Error())
require.Empty(t, resp.Warnings)
events.expectEvents(t, []expectedEvent{
{eventType: "gitlab/config-write"},
})
})
}
}