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:
@@ -59,14 +59,19 @@ jobs:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
-
|
||||
name: Install deps
|
||||
name: Install deps (ubuntu)
|
||||
if: startsWith(matrix.os, 'ubuntu-')
|
||||
run: |
|
||||
sudo apt-get update
|
||||
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
|
||||
if: startsWith(matrix.os, 'ubuntu-')
|
||||
if: ${{ !startsWith(matrix.os, 'windows-') }}
|
||||
uses: actions/github-script@v6
|
||||
id: gpg
|
||||
with:
|
||||
@@ -83,18 +88,21 @@ jobs:
|
||||
core.setOutput('passphrase', fs.readFileSync('.github/workflows/fixtures/7D851EB72D73BDA0.pass', {encoding: 'utf8'}));
|
||||
-
|
||||
name: Import GPG key
|
||||
if: startsWith(matrix.os, 'ubuntu-')
|
||||
if: ${{ !startsWith(matrix.os, 'windows-') }}
|
||||
uses: crazy-max/ghaction-import-gpg@v5
|
||||
with:
|
||||
gpg_private_key: ${{ steps.gpg.outputs.key }}
|
||||
passphrase: ${{ steps.gpg.outputs.passphrase }}
|
||||
trust_level: 5
|
||||
-
|
||||
name: Init pass
|
||||
if: ${{ !startsWith(matrix.os, 'windows-') }}
|
||||
run: |
|
||||
pass init 7D851EB72D73BDA0
|
||||
shell: bash
|
||||
-
|
||||
name: Test
|
||||
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 }}
|
||||
shell: bash
|
||||
-
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build darwin && cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "osxkeychain_darwin.h"
|
||||
#include "osxkeychain.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <stdio.h>
|
||||
@@ -1,10 +1,12 @@
|
||||
//go:build darwin && cgo
|
||||
|
||||
package osxkeychain
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -x objective-c
|
||||
#cgo LDFLAGS: -framework Security -framework Foundation
|
||||
|
||||
#include "osxkeychain_darwin.h"
|
||||
#include "osxkeychain.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build darwin && cgo
|
||||
|
||||
package osxkeychain
|
||||
|
||||
import (
|
||||
+75
-33
@@ -1,3 +1,5 @@
|
||||
//go:build !windows
|
||||
|
||||
package pass
|
||||
|
||||
import (
|
||||
@@ -8,75 +10,115 @@ import (
|
||||
)
|
||||
|
||||
func TestPassHelper(t *testing.T) {
|
||||
helper := Pass{}
|
||||
|
||||
creds := &credentials.Credentials{
|
||||
ServerURL: "https://foobar.docker.io:2376/v1",
|
||||
Username: "nothing",
|
||||
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"
|
||||
helper.Add(creds)
|
||||
u, s, err := helper.Get(creds.ServerURL)
|
||||
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()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
for server, username := range credsList {
|
||||
if !(strings.Contains(server, "2376") ||
|
||||
strings.Contains(server, "9999")) {
|
||||
t.Fatalf("invalid url: %s", creds.ServerURL)
|
||||
if !(strings.HasSuffix(server, "2376/v1") || strings.HasSuffix(server, "2375/v1")) {
|
||||
t.Errorf("invalid url: %s", server)
|
||||
}
|
||||
|
||||
if username != "nothing" {
|
||||
t.Fatalf("invalid username: %v", username)
|
||||
if !(username == "foo" || username == "bar") {
|
||||
t.Errorf("invalid username: %v", username)
|
||||
}
|
||||
|
||||
u, s, err := helper.Get(server)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if u != username {
|
||||
t.Fatalf("invalid username %s", u)
|
||||
t.Errorf("invalid username %s", u)
|
||||
}
|
||||
|
||||
if s != "isthebestmeshuggahalbum" {
|
||||
t.Fatalf("invalid secret: %s", s)
|
||||
t.Errorf("invalid secret: %s", s)
|
||||
}
|
||||
|
||||
err = helper.Delete(server)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if err := helper.Delete(server); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, _, err = helper.Get(server)
|
||||
if !credentials.IsErrCredentialsNotFound(err) {
|
||||
t.Fatalf("expected credentials not found, actual: %v", err)
|
||||
if _, _, err := helper.Get(server); !credentials.IsErrCredentialsNotFound(err) {
|
||||
t.Errorf("expected credentials not found, actual: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
credsList, err = helper.List()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(credsList) != 0 {
|
||||
t.Fatal("didn't delete all creds?")
|
||||
t.Error("didn't delete all creds?")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingCred(t *testing.T) {
|
||||
helper := Pass{}
|
||||
|
||||
_, _, err := helper.Get("garbage")
|
||||
if !credentials.IsErrCredentialsNotFound(err) {
|
||||
t.Fatalf("expected credentials not found, actual: %v", err)
|
||||
if _, _, err := helper.Get("garbage"); !credentials.IsErrCredentialsNotFound(err) {
|
||||
t.Errorf("expected credentials not found, actual: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build linux && cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "secretservice_linux.h"
|
||||
#include "secretservice.h"
|
||||
|
||||
const SecretSchema *docker_get_schema(void)
|
||||
{
|
||||
@@ -1,9 +1,11 @@
|
||||
//go:build linux && cgo
|
||||
|
||||
package secretservice
|
||||
|
||||
/*
|
||||
#cgo pkg-config: libsecret-1
|
||||
|
||||
#include "secretservice_linux.h"
|
||||
#include "secretservice.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build linux && cgo
|
||||
|
||||
package secretservice
|
||||
|
||||
import (
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build windows
|
||||
|
||||
package wincred
|
||||
|
||||
import (
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build windows
|
||||
|
||||
package wincred
|
||||
|
||||
import (
|
||||
Reference in New Issue
Block a user