mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-09 17:55:10 -04:00
AB#2523 Refactor GCP metadata/cloud API (#387)
* Refactor GCP metadata/cloud API * Remove cloud controller manager from metadata package * Remove PublicIP * Move shared cloud packages * Remove dead code Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
e9fecec0bc
commit
c9873f2bfb
54 changed files with 1587 additions and 3791 deletions
90
internal/cloud/azureshared/appcredentials_test.go
Normal file
90
internal/cloud/azureshared/appcredentials_test.go
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package azureshared
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
|
||||
func TestApplicationCredentialsFromURI(t *testing.T) {
|
||||
creds := ApplicationCredentials{
|
||||
TenantID: "tenant-id",
|
||||
AppClientID: "client-id",
|
||||
ClientSecretValue: "client-secret",
|
||||
Location: "location",
|
||||
}
|
||||
testCases := map[string]struct {
|
||||
cloudServiceAccountURI string
|
||||
wantCreds ApplicationCredentials
|
||||
wantErr bool
|
||||
}{
|
||||
"getApplicationCredentials works": {
|
||||
cloudServiceAccountURI: "serviceaccount://azure?tenant_id=tenant-id&client_id=client-id&client_secret=client-secret&location=location",
|
||||
wantCreds: creds,
|
||||
},
|
||||
"invalid URI fails": {
|
||||
cloudServiceAccountURI: "\x00",
|
||||
wantErr: true,
|
||||
},
|
||||
"incorrect URI scheme fails": {
|
||||
cloudServiceAccountURI: "invalid",
|
||||
wantErr: true,
|
||||
},
|
||||
"incorrect URI host fails": {
|
||||
cloudServiceAccountURI: "serviceaccount://incorrect",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
creds, err := ApplicationCredentialsFromURI(tc.cloudServiceAccountURI)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
assert.Equal(tc.wantCreds, creds)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToCloudServiceAccountURI(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
key := ApplicationCredentials{
|
||||
TenantID: "tenant-id",
|
||||
AppClientID: "client-id",
|
||||
ClientSecretValue: "client-secret",
|
||||
Location: "location",
|
||||
}
|
||||
|
||||
cloudServiceAccountURI := key.ToCloudServiceAccountURI()
|
||||
uri, err := url.Parse(cloudServiceAccountURI)
|
||||
require.NoError(err)
|
||||
query := uri.Query()
|
||||
assert.Equal("serviceaccount", uri.Scheme)
|
||||
assert.Equal("azure", uri.Host)
|
||||
assert.Equal(url.Values{
|
||||
"tenant_id": []string{"tenant-id"},
|
||||
"client_id": []string{"client-id"},
|
||||
"client_secret": []string{"client-secret"},
|
||||
"location": []string{"location"},
|
||||
}, query)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue