mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Prevent invalid credentials: no missing server URL or username (#62)
* Prevent invalid credentials: no missing server URL or username Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com> * Add missing username/serverURL error checks in credstore client Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com> * Clean up doc on invalid creds errors and client's error checks Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com> * Add tests for missing ServerURL/Username Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com> * Clean isValidCredsMessage prototype Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com> * Add test for missing server URL and more detailed error msg Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
committed by
GitHub
parent
79ab7059b0
commit
ed11c58ebf
@@ -73,6 +73,46 @@ func TestStore(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreMissingServerURL(t *testing.T) {
|
||||
creds := &Credentials{
|
||||
ServerURL: "",
|
||||
Username: "foo",
|
||||
Secret: "bar",
|
||||
}
|
||||
|
||||
b, err := json.Marshal(creds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in := bytes.NewReader(b)
|
||||
|
||||
h := newMemoryStore()
|
||||
|
||||
if err := Store(h, in); IsCredentialsMissingServerURL(err) == false {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreMissingUsername(t *testing.T) {
|
||||
creds := &Credentials{
|
||||
ServerURL: "https://index.docker.io/v1/",
|
||||
Username: "",
|
||||
Secret: "bar",
|
||||
}
|
||||
|
||||
b, err := json.Marshal(creds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in := bytes.NewReader(b)
|
||||
|
||||
h := newMemoryStore()
|
||||
|
||||
if err := Store(h, in); IsCredentialsMissingUsername(err) == false {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
serverURL := "https://index.docker.io/v1/"
|
||||
creds := &Credentials{
|
||||
@@ -115,6 +155,32 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMissingServerURL(t *testing.T) {
|
||||
serverURL := "https://index.docker.io/v1/"
|
||||
creds := &Credentials{
|
||||
ServerURL: serverURL,
|
||||
Username: "foo",
|
||||
Secret: "bar",
|
||||
}
|
||||
b, err := json.Marshal(creds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in := bytes.NewReader(b)
|
||||
|
||||
h := newMemoryStore()
|
||||
if err := Store(h, in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf := strings.NewReader("")
|
||||
w := new(bytes.Buffer)
|
||||
|
||||
if err := Get(h, buf, w); IsCredentialsMissingServerURL(err) == false {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErase(t *testing.T) {
|
||||
serverURL := "https://index.docker.io/v1/"
|
||||
creds := &Credentials{
|
||||
@@ -144,6 +210,30 @@ func TestErase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEraseMissingServerURL(t *testing.T) {
|
||||
serverURL := "https://index.docker.io/v1/"
|
||||
creds := &Credentials{
|
||||
ServerURL: serverURL,
|
||||
Username: "foo",
|
||||
Secret: "bar",
|
||||
}
|
||||
b, err := json.Marshal(creds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in := bytes.NewReader(b)
|
||||
|
||||
h := newMemoryStore()
|
||||
if err := Store(h, in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf := strings.NewReader("")
|
||||
if err := Erase(h, buf); IsCredentialsMissingServerURL(err) == false {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
//This tests that there is proper input an output into the byte stream
|
||||
//Individual stores are very OS specific and have been tested in osxkeychain and secretservice respectively
|
||||
|
||||
Reference in New Issue
Block a user