Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
-
Expand Down
2 changes: 2 additions & 0 deletions osxkeychain/cmd/main_darwin.go → osxkeychain/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin && cgo

package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "osxkeychain_darwin.h"
#include "osxkeychain.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/NSValue.h>
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin && cgo

package osxkeychain

import (
Expand Down
108 changes: 75 additions & 33 deletions pass/pass_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

package pass

import (
Expand All @@ -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)
}

if err := helper.Add(creds); err != nil {
t.Error(err)
}

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.Add(creds)
helper := Pass{}
if err := helper.checkInitialized(); err != nil {
t.Error(err)
}

creds.ServerURL = "https://foobar.docker.io:9999/v2"
helper.Add(creds)
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)
}
}
2 changes: 2 additions & 0 deletions secretservice/cmd/main_linux.go → secretservice/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux && cgo

package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string.h>
#include <stdlib.h>
#include "secretservice_linux.h"
#include "secretservice.h"

const SecretSchema *docker_get_schema(void)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux && cgo

package secretservice

import (
Expand Down
2 changes: 2 additions & 0 deletions wincred/cmd/main_windows.go → wincred/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions wincred/wincred_windows.go → wincred/wincred.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package wincred

import (
Expand Down
2 changes: 2 additions & 0 deletions wincred/wincred_windows_test.go → wincred/wincred_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package wincred

import (
Expand Down