-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
8,613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
ctx = context.Background() | ||
clientId, _ = os.LookupEnv("BATON_SERVICE_ACCOUNT_CLIENT_ID") | ||
clientSecret, _ = os.LookupEnv("BATON_SERVICE_ACCOUNT_CLIENT_SECRET") | ||
vaultId, _ = os.LookupEnv("BATON_VAULT") | ||
orgId, _ = os.LookupEnv("BATON_ORGANIZATION_ID") | ||
) | ||
|
||
const ( | ||
authType = "Bearer " | ||
baseUrl = "https://accounts.apps.verygoodsecurity.com" | ||
) | ||
|
||
func TestOrganizationResources(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
resource string | ||
}{ | ||
{ | ||
name: "Checking Members", | ||
resource: "members", | ||
}, | ||
{ | ||
name: "Checking Users", | ||
resource: "users", | ||
}, | ||
{ | ||
name: "Checking Invites", | ||
resource: "invites", | ||
}, | ||
} | ||
|
||
cli, err := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
assert.Nil(t, err) | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
endpointUrl, err := url.JoinPath(baseUrl, "organizations", orgId, test.resource) | ||
assert.Nil(t, err) | ||
|
||
uri, err := url.Parse(endpointUrl) | ||
assert.Nil(t, err) | ||
|
||
req, err := getRequestForTesting(cli, uri) | ||
assert.Nil(t, err) | ||
|
||
resp, err := cli.httpClient.Do(req) | ||
assert.Nil(t, err) | ||
|
||
defer resp.Body.Close() | ||
res, err := io.ReadAll(resp.Body) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, res) | ||
|
||
var data any | ||
err = json.Unmarshal(res, &data) | ||
assert.Nil(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestVaultMembers(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cli, err := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
assert.Nil(t, err) | ||
|
||
endpointUrl, err := url.JoinPath(baseUrl, "vaults", vaultId, "members") | ||
assert.Nil(t, err) | ||
|
||
uri, err := url.Parse(endpointUrl) | ||
assert.Nil(t, err) | ||
|
||
req, err := getRequestForTesting(cli, uri) | ||
assert.Nil(t, err) | ||
|
||
resp, err := cli.httpClient.Do(req) | ||
assert.Nil(t, err) | ||
|
||
defer resp.Body.Close() | ||
res, err := io.ReadAll(resp.Body) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, res) | ||
|
||
var data any | ||
err = json.Unmarshal(res, &data) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func getClientForTesting(ctx context.Context, clientId, clientSecret, orgId, vaultId string) (*VGSClient, error) { | ||
cli, err := New(ctx, clientId, clientSecret, orgId, vaultId) | ||
return cli, err | ||
} | ||
|
||
func TestVaults(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cli, err := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
assert.Nil(t, err) | ||
|
||
endpointUrl, err := url.JoinPath(baseUrl, "vaults") | ||
assert.Nil(t, err) | ||
|
||
uri, err := url.Parse(endpointUrl) | ||
assert.Nil(t, err) | ||
|
||
req, err := getRequestForTesting(cli, uri) | ||
assert.Nil(t, err) | ||
|
||
resp, err := cli.httpClient.Do(req) | ||
assert.Nil(t, err) | ||
|
||
defer resp.Body.Close() | ||
res, err := io.ReadAll(resp.Body) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, res) | ||
|
||
var data any | ||
err = json.Unmarshal(res, &data) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func getRequestForTesting(cli *VGSClient, uri *url.URL) (*http.Request, error) { | ||
req, err := cli.httpClient.NewRequest(ctx, | ||
http.MethodGet, | ||
uri, | ||
WithAcceptVndJSONHeader(), | ||
WithAuthorizationBearerHeader(cli.GetToken()), | ||
) | ||
return req, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package connector | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" | ||
"github.com/conductorone/baton-sdk/pkg/pagination" | ||
"github.com/conductorone/baton-vgs/pkg/client" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
clientId, _ = os.LookupEnv("BATON_SERVICE_ACCOUNT_CLIENT_ID") | ||
clientSecret, _ = os.LookupEnv("BATON_SERVICE_ACCOUNT_CLIENT_SECRET") | ||
vaultId, _ = os.LookupEnv("BATON_VAULT") | ||
orgId, _ = os.LookupEnv("BATON_ORGANIZATION_ID") | ||
ctx = context.Background() | ||
) | ||
|
||
func TestUserResourceTypeList(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
user := &userResourceType{ | ||
resourceType: &v2.ResourceType{}, | ||
client: getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId), | ||
} | ||
rs, _, _, err := user.List(ctx, &v2.ResourceId{}, &pagination.Token{}) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, rs) | ||
} | ||
|
||
func TestOrgResourceTypeList(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
org := &orgResourceType{ | ||
resourceType: &v2.ResourceType{}, | ||
client: getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId), | ||
} | ||
rs, _, _, err := org.List(ctx, &v2.ResourceId{}, &pagination.Token{}) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, rs) | ||
} | ||
|
||
func TestVaultResourceTypeList(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
vault := &vaultResourceType{ | ||
resourceType: &v2.ResourceType{}, | ||
client: getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId), | ||
} | ||
rs, _, _, err := vault.List(ctx, &v2.ResourceId{}, &pagination.Token{}) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, rs) | ||
} | ||
|
||
func getClientForTesting(ctx context.Context, clientId, clientSecret, orgId, vaultId string) *client.VGSClient { | ||
cli, _ := client.New(ctx, clientId, clientSecret, orgId, vaultId) | ||
return cli | ||
} | ||
|
||
func TestClient(t *testing.T) { | ||
cli, err := client.New(ctx, clientId, clientSecret, orgId, vaultId) | ||
assert.Nil(t, err) | ||
Check failure on line 71 in pkg/connector/internal_test.go
|
||
assert.NotNil(t, cli) | ||
Check failure on line 72 in pkg/connector/internal_test.go
|
||
} | ||
|
||
func TestListVaults(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
lv, err := cliTest.ListVaults(ctx) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, lv) | ||
} | ||
|
||
func TestListVaultUsers(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
lvu, err := cliTest.ListVaultUsers(ctx, vaultId) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, lvu) | ||
} | ||
|
||
func TestListUsers(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
lu, err := cliTest.ListUsers(ctx, orgId, vaultId) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, lu) | ||
} | ||
|
||
func TestListUserInvites(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
lui, err := cliTest.ListUserInvites(ctx, orgId) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, lui) | ||
} | ||
|
||
func TestListOrganizations(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
lo, err := cliTest.ListOrganizations(ctx) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, lo) | ||
} | ||
|
||
func TestUpdateVault(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
err := cliTest.UpdateUserAccessVault(ctx, vaultId, "ID9hRKLhcc6RWBvaHQ7L1Uan", "write") | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestRevokeVault(t *testing.T) { | ||
if clientId == "" && clientSecret == "" && orgId == "" && vaultId == "" { | ||
t.Skip() | ||
} | ||
|
||
cliTest := getClientForTesting(ctx, clientId, clientSecret, orgId, vaultId) | ||
err := cliTest.RevokeUserAccessVault(ctx, vaultId, "IDjSP9BVbJ3RnPr2FonGxXp5") | ||
assert.Nil(t, err) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.