mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 20:38:00 +00:00
425a8b5fd5
* fix(zitadelctl): implement takedown command * fix(zitadelctl): correct destroy flow * fix(zitadelctl): correct backup commands to read crds beforehand * fix: add of destroyfile * fix: clean for userlist * fix: change backup and restore to crdb native * fix: timeout for delete pvc for cockroachdb * fix: corrected unit tests * fix: add ignored file for scale * fix: correct handling of gitops in backup command * feat: add s3 backup kind * fix: backuplist for s3 and timeout for pv deletion * fix(database): fix nil pointer with binary version * fix(database): cleanup of errors which cam with merging of the s3 logic * fix: correct unit tests * fix: cleanup monitor output Co-authored-by: Elio Bischof <eliobischof@gmail.com> * fix: backup imagepullpolixy to ifnotpresent Co-authored-by: Elio Bischof <eliobischof@gmail.com>
156 lines
3.7 KiB
Go
156 lines
3.7 KiB
Go
package s3
|
|
|
|
import (
|
|
"github.com/caos/orbos/pkg/secret"
|
|
"github.com/caos/orbos/pkg/tree"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
masterkey = "testMk"
|
|
cron = "testCron"
|
|
bucketName = "testBucket"
|
|
region = "testRegion"
|
|
endpoint = "testEndpoint"
|
|
akid = "testAKID"
|
|
sak = "testSAK"
|
|
st = "testST"
|
|
yamlFile = `kind: databases.caos.ch/BucketBackup
|
|
version: v0
|
|
spec:
|
|
verbose: true
|
|
cron: testCron
|
|
bucket: testBucket
|
|
region: testRegion
|
|
endpoint: testEndpoint
|
|
accessKeyID:
|
|
encryption: AES256
|
|
encoding: Base64
|
|
value: l7GEXvmCT8hBXereT4FIG4j5vKQIycjS
|
|
secretAccessKey:
|
|
encryption: AES256
|
|
encoding: Base64
|
|
value: NWYnOpFpME-9FESqWi0bFQ3M6e0iNQw=
|
|
sessionToken:
|
|
encryption: AES256
|
|
encoding: Base64
|
|
value: xVY9pEXuh0Wbf2P2X_yThXwqRX08sA==
|
|
`
|
|
|
|
yamlFileWithoutSecret = `kind: databases.caos.ch/BucketBackup
|
|
version: v0
|
|
spec:
|
|
verbose: true
|
|
cron: testCron
|
|
bucket: testBucket
|
|
endpoint: testEndpoint
|
|
region: testRegion
|
|
`
|
|
yamlEmpty = `kind: databases.caos.ch/BucketBackup
|
|
version: v0`
|
|
)
|
|
|
|
var (
|
|
desired = DesiredV0{
|
|
Common: tree.NewCommon("databases.caos.ch/BucketBackup", "v0", false),
|
|
Spec: &Spec{
|
|
Verbose: true,
|
|
Cron: cron,
|
|
Bucket: bucketName,
|
|
Endpoint: endpoint,
|
|
Region: region,
|
|
AccessKeyID: &secret.Secret{
|
|
Value: akid,
|
|
Encryption: "AES256",
|
|
Encoding: "Base64",
|
|
},
|
|
SecretAccessKey: &secret.Secret{
|
|
Value: sak,
|
|
Encryption: "AES256",
|
|
Encoding: "Base64",
|
|
},
|
|
SessionToken: &secret.Secret{
|
|
Value: st,
|
|
Encryption: "AES256",
|
|
Encoding: "Base64",
|
|
},
|
|
},
|
|
}
|
|
desiredWithoutSecret = DesiredV0{
|
|
Common: tree.NewCommon("databases.caos.ch/BucketBackup", "v0", false),
|
|
Spec: &Spec{
|
|
Verbose: true,
|
|
Cron: cron,
|
|
Bucket: bucketName,
|
|
Region: region,
|
|
Endpoint: endpoint,
|
|
},
|
|
}
|
|
desiredEmpty = DesiredV0{
|
|
Common: tree.NewCommon("databases.caos.ch/BucketBackup", "v0", false),
|
|
Spec: &Spec{
|
|
Verbose: false,
|
|
Cron: "",
|
|
Bucket: "",
|
|
Endpoint: "",
|
|
Region: "",
|
|
AccessKeyID: &secret.Secret{
|
|
Value: "",
|
|
},
|
|
SecretAccessKey: &secret.Secret{
|
|
Value: "",
|
|
},
|
|
SessionToken: &secret.Secret{
|
|
Value: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
desiredNil = DesiredV0{
|
|
Common: tree.NewCommon("databases.caos.ch/BucketBackup", "v0", false),
|
|
}
|
|
)
|
|
|
|
func marshalYaml(t *testing.T, masterkey string, struc *DesiredV0) []byte {
|
|
secret.Masterkey = masterkey
|
|
data, err := yaml.Marshal(struc)
|
|
assert.NoError(t, err)
|
|
return data
|
|
}
|
|
|
|
func unmarshalYaml(t *testing.T, masterkey string, yamlFile []byte) *tree.Tree {
|
|
secret.Masterkey = masterkey
|
|
desiredTree := &tree.Tree{}
|
|
assert.NoError(t, yaml.Unmarshal(yamlFile, desiredTree))
|
|
return desiredTree
|
|
}
|
|
|
|
func getDesiredTree(t *testing.T, masterkey string, desired *DesiredV0) *tree.Tree {
|
|
return unmarshalYaml(t, masterkey, marshalYaml(t, masterkey, desired))
|
|
}
|
|
|
|
func TestBucket_DesiredParse(t *testing.T) {
|
|
assert.Equal(t, yamlFileWithoutSecret, string(marshalYaml(t, masterkey, &desiredWithoutSecret)))
|
|
|
|
desiredTree := unmarshalYaml(t, masterkey, []byte(yamlFile))
|
|
desiredKind, err := ParseDesiredV0(desiredTree)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, &desired, desiredKind)
|
|
}
|
|
|
|
func TestBucket_DesiredNotZero(t *testing.T) {
|
|
desiredTree := unmarshalYaml(t, masterkey, []byte(yamlFile))
|
|
desiredKind, err := ParseDesiredV0(desiredTree)
|
|
assert.NoError(t, err)
|
|
assert.False(t, desiredKind.Spec.IsZero())
|
|
}
|
|
|
|
func TestBucket_DesiredZero(t *testing.T) {
|
|
desiredTree := unmarshalYaml(t, masterkey, []byte(yamlEmpty))
|
|
desiredKind, err := ParseDesiredV0(desiredTree)
|
|
assert.NoError(t, err)
|
|
assert.True(t, desiredKind.Spec.IsZero())
|
|
}
|