2022-03-28 06:24:41 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/cli/azure/client"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetApplicationCredentials(t *testing.T) {
|
|
|
|
creds := client.ApplicationCredentials{
|
|
|
|
TenantID: "tenant-id",
|
|
|
|
ClientID: "client-id",
|
|
|
|
ClientSecret: "client-secret",
|
2022-03-29 11:31:18 -04:00
|
|
|
Location: "location",
|
2022-03-28 06:24:41 -04:00
|
|
|
}
|
|
|
|
testCases := map[string]struct {
|
|
|
|
cloudServiceAccountURI string
|
2022-04-26 10:54:05 -04:00
|
|
|
wantCreds client.ApplicationCredentials
|
|
|
|
wantErr bool
|
2022-03-28 06:24:41 -04:00
|
|
|
}{
|
|
|
|
"getApplicationCredentials works": {
|
2022-03-29 11:31:18 -04:00
|
|
|
cloudServiceAccountURI: "serviceaccount://azure?tenant_id=tenant-id&client_id=client-id&client_secret=client-secret&location=location",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantCreds: creds,
|
2022-03-28 06:24:41 -04:00
|
|
|
},
|
|
|
|
"invalid URI fails": {
|
|
|
|
cloudServiceAccountURI: "\x00",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-28 06:24:41 -04:00
|
|
|
},
|
|
|
|
"incorrect URI scheme fails": {
|
|
|
|
cloudServiceAccountURI: "invalid",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-28 06:24:41 -04:00
|
|
|
},
|
|
|
|
"incorrect URI host fails": {
|
|
|
|
cloudServiceAccountURI: "serviceaccount://incorrect",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-28 06:24:41 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
creds, err := getApplicationCredentials(tc.cloudServiceAccountURI)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-28 06:24:41 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantCreds, creds)
|
2022-03-28 06:24:41 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|