-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathclient_test.go
More file actions
80 lines (66 loc) · 2.5 KB
/
client_test.go
File metadata and controls
80 lines (66 loc) · 2.5 KB
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
75
76
77
78
79
80
package cyberark_test
import (
"crypto/x509"
"errors"
"testing"
"github.com/jetstack/venafi-connection-lib/http_client"
"github.com/stretchr/testify/require"
"k8s.io/klog/v2"
"k8s.io/klog/v2/ktesting"
"github.com/jetstack/preflight/internal/cyberark"
"github.com/jetstack/preflight/internal/cyberark/dataupload"
"github.com/jetstack/preflight/internal/cyberark/servicediscovery"
"github.com/jetstack/preflight/pkg/testutil"
"github.com/jetstack/preflight/pkg/version"
_ "k8s.io/klog/v2/ktesting/init"
)
// TestCyberArkClient_PutSnapshot_MockAPI demonstrates that NewDatauploadClient works with the mock API.
func TestCyberArkClient_PutSnapshot_MockAPI(t *testing.T) {
logger := ktesting.NewLogger(t, ktesting.DefaultConfig)
ctx := klog.NewContext(t.Context(), logger)
httpClient := testutil.FakeCyberArk(t)
cfg := cyberark.ClientConfig{
Subdomain: servicediscovery.MockDiscoverySubdomain,
Username: "test@example.com",
Secret: "somepassword",
}
cl, err := cyberark.NewDatauploadClient(ctx, httpClient, cfg)
require.NoError(t, err)
err = cl.PutSnapshot(ctx, dataupload.Snapshot{
ClusterID: "ffffffff-ffff-ffff-ffff-ffffffffffff",
AgentVersion: version.PreflightVersion,
})
require.NoError(t, err)
}
// TestCyberArkClient_PutSnapshot_RealAPI demonstrates that NewDatauploadClient works with the real inventory API.
//
// An API token is obtained by authenticating with the ARK_USERNAME and ARK_SECRET from the environment.
// ARK_SUBDOMAIN should be your tenant subdomain.
//
// To test against a tenant on the integration platform, also set:
// ARK_DISCOVERY_API=https://platform-discovery.integration-cyberark.cloud/
//
// To enable verbose request logging:
//
// go test ./internal/cyberark \
// -v -count 1 -run TestCyberArkClient_PutSnapshot_RealAPI -args -testing.v 6
func TestCyberArkClient_PutSnapshot_RealAPI(t *testing.T) {
logger := ktesting.NewLogger(t, ktesting.DefaultConfig)
ctx := klog.NewContext(t.Context(), logger)
var rootCAs *x509.CertPool
httpClient := http_client.NewDefaultClient(version.UserAgent(), rootCAs)
cfg, err := cyberark.LoadClientConfigFromEnvironment()
if err != nil {
if errors.Is(err, cyberark.ErrMissingEnvironmentVariables) {
t.Skipf("Skipping: %s", err)
}
require.NoError(t, err)
}
cl, err := cyberark.NewDatauploadClient(ctx, httpClient, cfg)
require.NoError(t, err)
err = cl.PutSnapshot(ctx, dataupload.Snapshot{
ClusterID: "ffffffff-ffff-ffff-ffff-ffffffffffff",
AgentVersion: version.PreflightVersion,
})
require.NoError(t, err)
}