mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 00:19:36 -05:00
2d8fcd9bf4
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetAzureValidator(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
ownerID string
|
|
clusterID string
|
|
errExpected bool
|
|
}{
|
|
"no input": {
|
|
ownerID: "",
|
|
clusterID: "",
|
|
errExpected: true,
|
|
},
|
|
"unencoded secret ID": {
|
|
ownerID: "owner-id",
|
|
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
|
errExpected: true,
|
|
},
|
|
"unencoded cluster ID": {
|
|
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
|
clusterID: "unique-id",
|
|
errExpected: true,
|
|
},
|
|
"correct input": {
|
|
ownerID: base64.StdEncoding.EncodeToString([]byte("owner-id")),
|
|
clusterID: base64.StdEncoding.EncodeToString([]byte("unique-id")),
|
|
errExpected: false,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
|
|
cmd := newVerifyAzureCmd()
|
|
cmd.Flags().String("owner-id", "", "")
|
|
cmd.Flags().String("unique-id", "", "")
|
|
require.NoError(cmd.Flags().Set("owner-id", tc.ownerID))
|
|
require.NoError(cmd.Flags().Set("unique-id", tc.clusterID))
|
|
var out bytes.Buffer
|
|
cmd.SetOut(&out)
|
|
var errOut bytes.Buffer
|
|
cmd.SetErr(&errOut)
|
|
|
|
_, err := getAzureValidator(cmd, map[uint32][]byte{
|
|
0: []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
|
|
1: []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"),
|
|
})
|
|
if tc.errExpected {
|
|
assert.Error(err)
|
|
} else {
|
|
assert.NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|