Merge pull request #13 from Mic92/fix-existing-files

This commit is contained in:
Jörg Thalheim 2020-07-20 00:16:31 +01:00 committed by GitHub
commit 2fb90c84a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 26 deletions

View file

@ -24,6 +24,9 @@ jobs:
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: Show nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- name: Run golangci-lint
run: nix-shell --pure --run "golangci-lint run"
if: matrix.nixPath == 'nixpkgs=channel:nixpkgs-unstable'
- name: Build nix packages
run: nix run nixpkgs.nix-build-uncached -c nix-build-uncached default.nix
- name: Add keys group (needed for go tests)

View file

@ -36,18 +36,18 @@ func TestShellHook(t *testing.T) {
cmd.Stderr = &stderrBuf
cmd.Dir = assets
err = cmd.Run()
stdout := string(stdoutBuf.Bytes())
stderr := string(stderrBuf.Bytes())
stdout := stdoutBuf.String()
stderr := stderrBuf.String()
fmt.Printf("$ %s\nstdout: \n%s\nstderr: \n%s\n", strings.Join(cmd.Args, " "), stdout, stderr)
ok(t, err)
expectedStdout := "SOPS_PGP_FP=C6DA56E69A7C756564A8AFEB4A6B05B714D13EFD,4EC40F8E04A945339F7F7C0032C5225271038E3F,7FB89715AADA920D65D25E63F9BA9DEBD03F57C0"
if strings.Index(stdout, expectedStdout) == -1 {
if !strings.Contains(stdout, expectedStdout) {
t.Fatalf("'%v' not in '%v'", expectedStdout, stdout)
}
expectedStderr := "./non-existing-key.gpg does not exists"
if strings.Index(stderr, expectedStderr) == -1 {
if !strings.Contains(stderr, expectedStderr) {
t.Fatalf("'%v' not in '%v'", expectedStderr, stdout)
}

View file

@ -25,7 +25,10 @@ func parseFlags(args []string) options {
f.StringVar(&opts.format, "format", "armor", "GPG format encoding (binary|armor)")
f.StringVar(&opts.in, "i", "-", "Input path. Reads by default from standard output")
f.StringVar(&opts.out, "o", "-", "Output path. Prints by default to standard output")
f.Parse(args[1:])
if err := f.Parse(args[1:]); err != nil {
// should never happen since flag.ExitOnError
panic(err)
}
return opts
}

View file

@ -12,27 +12,6 @@ import (
"golang.org/x/crypto/ssh"
)
func parsePublicKey(publicKey []byte) (*rsa.PublicKey, error) {
key, _, _, _, err := ssh.ParseAuthorizedKey(publicKey)
if err != nil {
return nil, fmt.Errorf("failed to parse public ssh key: %s", err)
}
cryptoPublicKey, ok := key.(ssh.CryptoPublicKey)
if !ok {
return nil, fmt.Errorf("Unsupported public key algo: %s", key.Type())
}
rsaKey, ok := cryptoPublicKey.CryptoPublicKey().(*rsa.PublicKey)
if !ok {
return nil, fmt.Errorf("Unsupported public key algo: %s", key.Type())
}
return rsaKey, nil
}
func parsePrivateKey(sshPrivateKey []byte) (*rsa.PrivateKey, error) {
privateKey, err := ssh.ParseRawPrivateKey(sshPrivateKey)
if err != nil {

View file

@ -7,6 +7,7 @@ pkgs.mkShell {
gnupg
utillinux
nix
golangci-lint
];
# delve does not compile with hardening enabled
hardeningDisable = [ "all" ];