1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-15 08:52:10 +05:30

Merge pull request #289 from crazy-max/build-constraint

chore: use go build constraint
This commit is contained in:
Sebastiaan van Stijn
2023-05-29 17:54:04 +02:00
committed by GitHub
15 changed files with 112 additions and 44 deletions
+15 -7
View File
@@ -59,14 +59,19 @@ jobs:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
cache: true cache: true
- -
name: Install deps name: Install deps (ubuntu)
if: startsWith(matrix.os, 'ubuntu-') if: startsWith(matrix.os, 'ubuntu-')
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y dbus-x11 gnome-keyring libsecret-1-dev pass sudo apt-get install -y dbus-x11 gnome-keyring libsecret-1-dev pass
-
name: Install deps (macOS)
if: startsWith(matrix.os, 'macOS-')
run: |
brew install pass
- -
name: GPG conf name: GPG conf
if: startsWith(matrix.os, 'ubuntu-') if: ${{ !startsWith(matrix.os, 'windows-') }}
uses: actions/github-script@v6 uses: actions/github-script@v6
id: gpg id: gpg
with: with:
@@ -83,18 +88,21 @@ jobs:
core.setOutput('passphrase', fs.readFileSync('.github/workflows/fixtures/7D851EB72D73BDA0.pass', {encoding: 'utf8'})); core.setOutput('passphrase', fs.readFileSync('.github/workflows/fixtures/7D851EB72D73BDA0.pass', {encoding: 'utf8'}));
- -
name: Import GPG key name: Import GPG key
if: startsWith(matrix.os, 'ubuntu-') if: ${{ !startsWith(matrix.os, 'windows-') }}
uses: crazy-max/ghaction-import-gpg@v5 uses: crazy-max/ghaction-import-gpg@v5
with: with:
gpg_private_key: ${{ steps.gpg.outputs.key }} gpg_private_key: ${{ steps.gpg.outputs.key }}
passphrase: ${{ steps.gpg.outputs.passphrase }} passphrase: ${{ steps.gpg.outputs.passphrase }}
trust_level: 5
-
name: Init pass
if: ${{ !startsWith(matrix.os, 'windows-') }}
run: |
pass init 7D851EB72D73BDA0
shell: bash
- -
name: Test name: Test
run: | run: |
if [[ "${{ matrix.os }}" = ubuntu-* ]]; then
echo -e "trust\n5\ny" | gpg --batch --no-tty --command-fd 0 --edit-key 7D851EB72D73BDA0
pass init 7D851EB72D73BDA0
fi
make test COVERAGEDIR=${{ env.DESTDIR }} make test COVERAGEDIR=${{ env.DESTDIR }}
shell: bash shell: bash
- -
@@ -1,3 +1,5 @@
//go:build darwin && cgo
package main package main
import ( import (
@@ -1,4 +1,4 @@
#include "osxkeychain_darwin.h" #include "osxkeychain.h"
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <Foundation/NSValue.h> #include <Foundation/NSValue.h>
#include <stdio.h> #include <stdio.h>
@@ -1,10 +1,12 @@
//go:build darwin && cgo
package osxkeychain package osxkeychain
/* /*
#cgo CFLAGS: -x objective-c #cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Security -framework Foundation #cgo LDFLAGS: -framework Security -framework Foundation
#include "osxkeychain_darwin.h" #include "osxkeychain.h"
#include <stdlib.h> #include <stdlib.h>
*/ */
import "C" import "C"
@@ -1,3 +1,5 @@
//go:build darwin && cgo
package osxkeychain package osxkeychain
import ( import (
+75 -33
View File
@@ -1,3 +1,5 @@
//go:build !windows
package pass package pass
import ( import (
@@ -8,75 +10,115 @@ import (
) )
func TestPassHelper(t *testing.T) { func TestPassHelper(t *testing.T) {
helper := Pass{}
creds := &credentials.Credentials{ creds := &credentials.Credentials{
ServerURL: "https://foobar.docker.io:2376/v1", ServerURL: "https://foobar.docker.io:2376/v1",
Username: "nothing", Username: "nothing",
Secret: "isthebestmeshuggahalbum", Secret: "isthebestmeshuggahalbum",
} }
_ = helper.CheckInitialized() helper := Pass{}
if err := helper.checkInitialized(); err != nil {
t.Error(err)
}
helper.Add(creds) if err := helper.Add(creds); err != nil {
t.Error(err)
}
creds.ServerURL = "https://foobar.docker.io:9999/v2" u, s, err := helper.Get(creds.ServerURL)
helper.Add(creds) if err != nil {
t.Error(err)
}
if u != creds.Username {
t.Errorf("invalid username %s", u)
}
if s != creds.Secret {
t.Errorf("invalid secret: %s", s)
}
if err := helper.Delete(creds.ServerURL); err != nil {
t.Error(err)
}
if _, _, err := helper.Get(creds.ServerURL); !credentials.IsErrCredentialsNotFound(err) {
t.Errorf("expected credentials not found, actual: %v", err)
}
}
func TestPassHelperCheckInit(t *testing.T) {
helper := Pass{}
if v := helper.CheckInitialized(); !v {
t.Errorf("expected true, actual: %v", v)
}
}
func TestPassHelperList(t *testing.T) {
creds := []*credentials.Credentials{
{
ServerURL: "https://foobar.docker.io:2376/v1",
Username: "foo",
Secret: "isthebestmeshuggahalbum",
},
{
ServerURL: "https://foobar.docker.io:2375/v1",
Username: "bar",
Secret: "isthebestmeshuggahalbum",
},
}
helper := Pass{}
if err := helper.checkInitialized(); err != nil {
t.Error(err)
}
for _, cred := range creds {
if err := helper.Add(cred); err != nil {
t.Error(err)
}
}
credsList, err := helper.List() credsList, err := helper.List()
if err != nil { if err != nil {
t.Fatal(err) t.Error(err)
} }
for server, username := range credsList { for server, username := range credsList {
if !(strings.Contains(server, "2376") || if !(strings.HasSuffix(server, "2376/v1") || strings.HasSuffix(server, "2375/v1")) {
strings.Contains(server, "9999")) { t.Errorf("invalid url: %s", server)
t.Fatalf("invalid url: %s", creds.ServerURL)
} }
if !(username == "foo" || username == "bar") {
if username != "nothing" { t.Errorf("invalid username: %v", username)
t.Fatalf("invalid username: %v", username)
} }
u, s, err := helper.Get(server) u, s, err := helper.Get(server)
if err != nil { if err != nil {
t.Fatal(err) t.Error(err)
} }
if u != username { if u != username {
t.Fatalf("invalid username %s", u) t.Errorf("invalid username %s", u)
} }
if s != "isthebestmeshuggahalbum" { if s != "isthebestmeshuggahalbum" {
t.Fatalf("invalid secret: %s", s) t.Errorf("invalid secret: %s", s)
} }
err = helper.Delete(server) if err := helper.Delete(server); err != nil {
if err != nil { t.Error(err)
t.Fatal(err)
} }
if _, _, err := helper.Get(server); !credentials.IsErrCredentialsNotFound(err) {
_, _, err = helper.Get(server) t.Errorf("expected credentials not found, actual: %v", err)
if !credentials.IsErrCredentialsNotFound(err) {
t.Fatalf("expected credentials not found, actual: %v", err)
} }
} }
credsList, err = helper.List() credsList, err = helper.List()
if err != nil { if err != nil {
t.Fatal(err) t.Error(err)
} }
if len(credsList) != 0 { if len(credsList) != 0 {
t.Fatal("didn't delete all creds?") t.Error("didn't delete all creds?")
} }
} }
func TestMissingCred(t *testing.T) { func TestMissingCred(t *testing.T) {
helper := Pass{} helper := Pass{}
if _, _, err := helper.Get("garbage"); !credentials.IsErrCredentialsNotFound(err) {
_, _, err := helper.Get("garbage") t.Errorf("expected credentials not found, actual: %v", err)
if !credentials.IsErrCredentialsNotFound(err) {
t.Fatalf("expected credentials not found, actual: %v", err)
} }
} }
@@ -1,3 +1,5 @@
//go:build linux && cgo
package main package main
import ( import (
@@ -1,6 +1,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "secretservice_linux.h" #include "secretservice.h"
const SecretSchema *docker_get_schema(void) const SecretSchema *docker_get_schema(void)
{ {
@@ -1,9 +1,11 @@
//go:build linux && cgo
package secretservice package secretservice
/* /*
#cgo pkg-config: libsecret-1 #cgo pkg-config: libsecret-1
#include "secretservice_linux.h" #include "secretservice.h"
#include <stdlib.h> #include <stdlib.h>
*/ */
import "C" import "C"
@@ -1,3 +1,5 @@
//go:build linux && cgo
package secretservice package secretservice
import ( import (
@@ -1,3 +1,5 @@
//go:build windows
package main package main
import ( import (
@@ -1,3 +1,5 @@
//go:build windows
package wincred package wincred
import ( import (
@@ -1,3 +1,5 @@
//go:build windows
package wincred package wincred
import ( import (