-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gardener config credential repository #55
Changes from 1 commit
786edce
0cb6e36
f710aee
302ffbb
8ab9366
938cfb6
4e86cc0
dcae60d
734c8c5
bd82787
d438e8e
314dcd9
d42f6ad
b41d116
19afc32
651e0b1
58870c0
71649a2
df967b8
7dba5bc
71baf49
3c08c1e
1521565
93d2bc8
94d51b9
5c916d8
50a0c94
52eaa24
016112e
b8b933a
9e16811
c877f6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,11 @@ import ( | |
local "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/gardenerconfig" | ||
gardenercfgcpi "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/gardenerconfig/cpi" | ||
"github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" | ||
"github.com/open-component-model/ocm/pkg/contexts/oci/identity" | ||
) | ||
|
||
var _ = Describe("gardener config", func() { | ||
props := common.Properties{ | ||
"username": "abc", | ||
"password": "123", | ||
} | ||
|
||
creds := `{ | ||
containerRegistryCfg := `{ | ||
"container_registry": { | ||
"test-credentials": { | ||
"username": "abc", | ||
|
@@ -42,9 +38,20 @@ var _ = Describe("gardener config", func() { | |
} | ||
}` | ||
encryptionKey := "abcdefghijklmnop" | ||
encryptedCredentials := "Uz4mfePXFOUbjUEZnRrnG8zP2T7lRH6bR2rFHYgWDwZUXfW7D5wArwY4dsBACPVFNapF7kcM9z79+LvJXd2kNoIfvUyMOhrSDAyv4LtUqYSKBOoRH/aJMnXjmN9GQBCXSRSJs/Fu21AoDNo8fA9zYvvc7WxTldkYC/vHxLVNJu5j176e1QiaS9hwDjgNhgyUT3XUjHUyQ19PcRgwDglRLfiL4Cs/fYPPxdg4YZQdCnc=" | ||
encryptedContainerRegistryCfg := "Uz4mfePXFOUbjUEZnRrnG8zP2T7lRH6bR2rFHYgWDwZUXfW7D5wArwY4dsBACPVFNapF7kcM9z79+LvJXd2kNoIfvUyMOhrSDAyv4LtUqYSKBOoRH/aJMnXjmN9GQBCXSRSJs/Fu21AoDNo8fA9zYvvc7WxTldkYC/vHxLVNJu5j176e1QiaS9hwDjgNhgyUT3XUjHUyQ19PcRgwDglRLfiL4Cs/fYPPxdg4YZQdCnc=" | ||
|
||
specTemplate := `{"type":"GardenerConfig","url":"%s","configType":"container_registry","cipher":"%s","propagateConsumerIdentity":true}` | ||
expectedConsumerId := cpi.ConsumerIdentity{ | ||
cpi.CONSUMER_ATTR_TYPE: identity.CONSUMER_TYPE, | ||
hostpath.ID_HOSTNAME: "eu.gcr.io", | ||
hostpath.ID_PATHPREFIX: "test-project", | ||
} | ||
|
||
expectedCreds := cpi.NewCredentials(common.Properties{ | ||
cpi.ATTR_USERNAME: "abc", | ||
cpi.ATTR_PASSWORD: "123", | ||
}) | ||
|
||
repoSpecTemplate := `{"type":"GardenerConfig","url":"%s","configType":"container_registry","cipher":"%s","propagateConsumerIdentity":true}` | ||
|
||
var defaultContext credentials.Context | ||
|
||
|
@@ -57,7 +64,7 @@ var _ = Describe("gardener config", func() { | |
url = "http://localhost:8080/container_registry" | ||
cipher = local.Plaintext | ||
) | ||
expectedSpec := fmt.Sprintf(specTemplate, url, cipher) | ||
expectedSpec := fmt.Sprintf(repoSpecTemplate, url, cipher) | ||
|
||
spec := local.NewRepositorySpec("http://localhost:8080/container_registry", "container_registry", local.Plaintext, true) | ||
data, err := json.Marshal(spec) | ||
|
@@ -70,7 +77,7 @@ var _ = Describe("gardener config", func() { | |
url = "http://localhost:8080/container_registry" | ||
cipher = local.Plaintext | ||
) | ||
specdata := fmt.Sprintf(specTemplate, url, cipher) | ||
specdata := fmt.Sprintf(repoSpecTemplate, url, cipher) | ||
|
||
spec, err := defaultContext.RepositorySpecForConfig([]byte(specdata), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
@@ -85,12 +92,12 @@ var _ = Describe("gardener config", func() { | |
It("resolves repository", func() { | ||
svr := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(200) | ||
_, err := writer.Write([]byte(creds)) | ||
_, err := writer.Write([]byte(containerRegistryCfg)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
})) | ||
defer svr.Close() | ||
|
||
specdata := fmt.Sprintf(specTemplate, svr.URL, local.Plaintext) | ||
specdata := fmt.Sprintf(repoSpecTemplate, svr.URL, local.Plaintext) | ||
|
||
repo, err := defaultContext.RepositoryForConfig([]byte(specdata), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
@@ -101,26 +108,32 @@ var _ = Describe("gardener config", func() { | |
It("retrieves credentials from unencrypted server", func() { | ||
svr := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(200) | ||
_, err := writer.Write([]byte(creds)) | ||
_, err := writer.Write([]byte(containerRegistryCfg)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
})) | ||
defer svr.Close() | ||
|
||
spec := fmt.Sprintf(specTemplate, svr.URL, local.Plaintext) | ||
spec := fmt.Sprintf(repoSpecTemplate, svr.URL, local.Plaintext) | ||
|
||
repo, err := defaultContext.RepositoryForConfig([]byte(spec), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(repo).ToNot(BeNil()) | ||
|
||
credentials, err := repo.LookupCredentials("test-credentials") | ||
credentialsFromRepo, err := repo.LookupCredentials("test-credentials") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentials.Properties()).To(Equal(props)) | ||
Expect(credentialsFromRepo).To(Equal(expectedCreds)) | ||
|
||
credSrc, err := defaultContext.GetCredentialsForConsumer(expectedConsumerId, hostpath.IdentityMatcher(identity.CONSUMER_TYPE)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should use your identity matcher object provided by the package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should bundle the consumer test in a dedicated test with the focus of testing the consumer propagation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
Expect(err).ToNot(HaveOccurred()) | ||
credentialsFromCtx, err := credSrc.Credentials(defaultContext) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentialsFromCtx).To(Equal(expectedCreds)) | ||
}) | ||
|
||
It("retrieves credentials from encrypted server", func() { | ||
svr := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(200) | ||
data, err := base64.StdEncoding.DecodeString(encryptedCredentials) | ||
data, err := base64.StdEncoding.DecodeString(encryptedContainerRegistryCfg) | ||
Expect(err).ToNot(HaveOccurred()) | ||
_, err = writer.Write(data) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
@@ -144,16 +157,21 @@ var _ = Describe("gardener config", func() { | |
|
||
defaultContext.SetCredentialsForConsumer(id, creds) | ||
|
||
spec := fmt.Sprintf(specTemplate, svr.URL, local.AESECB) | ||
spec := fmt.Sprintf(repoSpecTemplate, svr.URL, local.AESECB) | ||
|
||
repo, err := defaultContext.RepositoryForConfig([]byte(spec), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(repo).ToNot(BeNil()) | ||
|
||
credentials, err := repo.LookupCredentials("test-credentials") | ||
credentialsFromRepo, err := repo.LookupCredentials("test-credentials") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentialsFromRepo).To(Equal(expectedCreds)) | ||
|
||
Expect(credentials.Properties()).To(Equal(props)) | ||
credSrc, err := defaultContext.GetCredentialsForConsumer(expectedConsumerId, hostpath.IdentityMatcher(identity.CONSUMER_TYPE)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
credentialsFromCtx, err := credSrc.Credentials(defaultContext) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentialsFromCtx).To(Equal(expectedCreds)) | ||
}) | ||
|
||
It("retrieves credentials from file", func() { | ||
|
@@ -164,22 +182,27 @@ var _ = Describe("gardener config", func() { | |
file, err := fs.Create(filename) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
_, err = file.Write([]byte(creds)) | ||
_, err = file.Write([]byte(containerRegistryCfg)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = file.Close() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
spec := fmt.Sprintf(specTemplate, "file://"+filename, local.Plaintext) | ||
spec := fmt.Sprintf(repoSpecTemplate, "file://"+filename, local.Plaintext) | ||
|
||
repo, err := defaultContext.RepositoryForConfig([]byte(spec), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(repo).ToNot(BeNil()) | ||
|
||
credentials, err := repo.LookupCredentials("test-credentials") | ||
credentialsFromRepo, err := repo.LookupCredentials("test-credentials") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentialsFromRepo).To(Equal(expectedCreds)) | ||
|
||
Expect(credentials.Properties()).To(Equal(props)) | ||
credSrc, err := defaultContext.GetCredentialsForConsumer(expectedConsumerId, hostpath.IdentityMatcher(identity.CONSUMER_TYPE)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
credentialsFromCtx, err := credSrc.Credentials(defaultContext) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(credentialsFromCtx).To(Equal(expectedCreds)) | ||
}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should test whether the provided credentials are properly propagated to their consumer ids. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to instantiate the repository, if the server is currently not available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done