Skip to content

Commit

Permalink
Bump actions (#51)
Browse files Browse the repository at this point in the history
* bump

* fix go version

* fix linter

* disable depguard

* fix test
  • Loading branch information
enrichman authored Feb 27, 2024
1 parent bd86c9d commit a2ebd87
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.22

- name: Build
run: go build -v ./...
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ name: golangci-lint

on:
push:
tags:
- v*
branches:
- master
- main
tags: [ "*" ]
branches: [ "main" ]
pull_request:

permissions:
Expand All @@ -19,13 +16,13 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.22

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
10 changes: 5 additions & 5 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name: goreleaser

on:
pull_request:
push:
tags: [ "*" ]

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.22

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ linters:
- ifshort
- golint

# warn for generics: https://github.com/golangci/golangci-lint/issues/2649
- rowserrcheck
- sqlclosecheck
- wastedassign

# others
- forbidigo

Expand All @@ -39,3 +34,4 @@ linters:
- exhaustruct
- godox
- paralleltest
- depguard
2 changes: 1 addition & 1 deletion internal/cli/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If provided keys or images will be ignored`)
return decryptCmd
}

func runDecryptCmd(cmd *cobra.Command, args []string) error {
func runDecryptCmd(cmd *cobra.Command, _ []string) error {
if encryptedFile == "" {
return errors.New("missing file to decrypt. Use -f/--file flag")
}
Expand Down
11 changes: 6 additions & 5 deletions internal/cli/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/enrichman/stegosecrets/internal/cli"
"github.com/enrichman/stegosecrets/pkg/file"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const testAssetsDir = "../../test/assets/p5t3/"
Expand All @@ -19,7 +20,7 @@ func TestDecryptCmd_NoInput(t *testing.T) {
rootCmd.SetArgs([]string{"decrypt"})

err := rootCmd.Execute()
assert.NotNil(t, err)
assert.Error(t, err)
}

func TestDecryptCmd(t *testing.T) {
Expand Down Expand Up @@ -79,16 +80,16 @@ func TestDecryptCmd(t *testing.T) {

err := rootCmd.Execute()
if tc.wantExecuteErr {
assert.NotNil(t, err, outAndErr)
require.Error(t, err, outAndErr)
} else {
assert.Nil(t, err, outAndErr)
require.NoError(t, err, outAndErr)
}

err = file.Check(testAssetsDir+"secret", testAssetsDir+"secret.checksum")
if tc.wantCheckErr {
assert.NotNil(t, err, outAndErr)
require.Error(t, err, outAndErr)
} else {
assert.Nil(t, err, outAndErr)
require.NoError(t, err, outAndErr)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ If empty no images will be generated.`)
return encryptCmd
}

func runEncryptCmd(cmd *cobra.Command, args []string) error {
func runEncryptCmd(cmd *cobra.Command, _ []string) error {
if keyThreshold > keyParts {
return errors.Errorf("threshold %d cannot exceed the parts %d", keyThreshold, keyParts)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/enrichman/stegosecrets/internal/cli"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func setupTest(tb testing.TB) func(tb testing.TB) {
Expand All @@ -19,7 +20,7 @@ func setupTest(tb testing.TB) func(tb testing.TB) {
tb.Log("teardown test")

assert.DirExists(tb, "out")
assert.Nil(tb, os.RemoveAll("out"))
assert.NoError(tb, os.RemoveAll("out"))
}
}

Expand All @@ -33,7 +34,7 @@ func TestEncryptCmd_NoInput(t *testing.T) {
assert.NoDirExists(t, "out")

err := rootCmd.Execute()
assert.NotNil(t, err)
require.Error(t, err)
assert.NoDirExists(t, "out")
}

Expand All @@ -54,7 +55,7 @@ func TestEncryptCmd_Stdin(t *testing.T) {
assert.NoDirExists(t, "out")

err := rootCmd.Execute()
assert.Nil(t, err, outAndErr)
require.NoError(t, err, outAndErr)

assert.DirExists(t, "out")
assert.FileExists(t, "out/secret.enc")
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
errInvalidNumOfImages = errors.New("number of images must be at least 1")
)

func runImagesCmd(cmd *cobra.Command, args []string) error {
func runImagesCmd(_ *cobra.Command, _ []string) error {
if imagesNum == 0 {
return errInvalidNumOfImages
}
Expand Down
1 change: 1 addition & 0 deletions internal/decrypt/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (d *Decrypter) Decrypt(filename string) error {
key = d.MasterKey
} else {
d.Logger.Print("Decrypting with partial keys")

key, err = sss.Combine(d.Parts)
if err != nil {
return errors.Wrap(err, "failed combining parts")
Expand Down
4 changes: 2 additions & 2 deletions internal/encrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (e *Encrypter) generateAndSaveMasterKey(filename string) ([]byte, error) {
return nil, errors.Wrap(err, "failed generating master key")
}

encFilename := filepath.Join(e.OutputDir, fmt.Sprintf("%s.enc", filename))
encFilename := filepath.Join(e.OutputDir, filename+".enc")

err = file.WriteKey(e.Logger, masterKey, encFilename)
if err != nil {
Expand All @@ -163,7 +163,7 @@ func (e *Encrypter) encryptAndSaveMessage(masterKey []byte, reader io.Reader, fi
return errors.Wrap(err, "failed encrypting message")
}

encryptedFilename := filepath.Join(e.OutputDir, fmt.Sprintf("%s.enc", filename))
encryptedFilename := filepath.Join(e.OutputDir, filename+".enc")

err = file.WriteFile(e.Logger, encryptedMessage, encryptedFilename)
if err != nil {
Expand Down
29 changes: 15 additions & 14 deletions internal/encrypt/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/enrichman/stegosecrets/internal/encrypt"
"github.com/enrichman/stegosecrets/internal/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewEncrypter_WithPartsThreshold(t *testing.T) {
Expand Down Expand Up @@ -59,10 +60,10 @@ func TestNewEncrypter_WithPartsThreshold(t *testing.T) {
)

if tc.wantErr {
assert.NotNil(t, err)
require.Error(t, err)
assert.Nil(t, encrypter)
} else {
assert.Nil(t, err)
require.NoError(t, err)
assert.NotNil(t, encrypter)
}
})
Expand All @@ -73,20 +74,20 @@ func TestNewEncrypter_WithOutputDir(t *testing.T) {
// it should create the output dir
t.Run("non existing dir", func(t *testing.T) {
dir := filepath.Join(os.TempDir(), "non-existing-dir")
assert.Nil(t, os.RemoveAll(dir))
require.NoError(t, os.RemoveAll(dir))

_, err := os.Stat(dir)
assert.ErrorIs(t, err, fs.ErrNotExist)
require.ErrorIs(t, err, fs.ErrNotExist)

encrypter, err := encrypt.NewEncrypter(
encrypt.WithOutputDir(dir),
)

assert.Nil(t, err)
require.NoError(t, err)
assert.NotNil(t, encrypter)

_, err = os.Stat(dir)
assert.Nil(t, err)
assert.NoError(t, err)
})
}

Expand All @@ -98,18 +99,18 @@ func TestNewEncrypter_WithImagesDir(t *testing.T) {
encrypt.WithImagesDir(imagesDir),
)

assert.Nil(t, err)
require.NoError(t, err)
assert.NotNil(t, encrypter)

absoluteImagesDir, err := filepath.Abs(imagesDir)
assert.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, absoluteImagesDir, encrypter.ImagesDir)
})
}

func TestEncrypt(t *testing.T) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "out-*")
assert.Nil(t, err)
require.NoError(t, err)
assert.DirExists(t, tmpDir)

encrypter, err := encrypt.NewEncrypter(
Expand All @@ -118,10 +119,10 @@ func TestEncrypt(t *testing.T) {
encrypt.WithImagesDir("../../test/assets/p5t3"),
encrypt.WithLogger(log.NewSimpleLogger(io.Discard, log.None)),
)
assert.Nil(t, err)
require.NoError(t, err)

err = encrypter.Encrypt(strings.NewReader("hello world!"), "secret")
assert.Nil(t, err)
require.NoError(t, err)

assert.DirExists(t, tmpDir)
assert.FileExists(t, tmpDir+"/secret.enc")
Expand All @@ -130,11 +131,11 @@ func TestEncrypt(t *testing.T) {
assert.FileExists(t, tmpDir+"/secret.enc.checksum")

for i := 1; i <= 5; i++ {
assert.FileExists(t, fmt.Sprintf("%s/%03d.jpg", tmpDir, i))
assert.FileExists(t, fmt.Sprintf("%s/%03d.jpg.checksum", tmpDir, i))
assert.FileExists(t, fmt.Sprintf("%s/%03d.png", tmpDir, i))
assert.FileExists(t, fmt.Sprintf("%s/%03d.png.checksum", tmpDir, i))
assert.FileExists(t, fmt.Sprintf("%s/%03d.key", tmpDir, i))
}

err = os.RemoveAll(tmpDir)
assert.Nil(t, err)
require.NoError(t, err)
}
7 changes: 4 additions & 3 deletions pkg/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package file
import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -38,13 +39,13 @@ func WriteChecksum(logger log.Logger, content []byte, filename string) error {

checksum := fmt.Sprintf("%x\t%s", h.Sum(nil), filepath.Base(filename))

return WriteFile(logger, []byte(checksum), fmt.Sprintf("%s.checksum", filename))
return WriteFile(logger, []byte(checksum), filename+".checksum")
}

func WriteKey(logger log.Logger, key []byte, filename string) error {
base64EncodedKey := base64.StdEncoding.EncodeToString(key)

return WriteFile(logger, []byte(base64EncodedKey), fmt.Sprintf("%s.key", filename))
return WriteFile(logger, []byte(base64EncodedKey), filename+".key")
}

func WriteFile(logger log.Logger, content []byte, filename string) error {
Expand Down Expand Up @@ -118,7 +119,7 @@ func Check(filename, checksumFilename string) error {
}

checksumToVerify := strings.Split(string(checksumFileContent), "\t")[0]
checksumContent := fmt.Sprintf("%x", h.Sum(nil))
checksumContent := hex.EncodeToString(h.Sum(nil))

if checksumToVerify != checksumContent {
return errors.New("failed checksum verification")
Expand Down
3 changes: 1 addition & 2 deletions pkg/file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file_test

import (
"fmt"
"os"
"path"
"testing"
Expand All @@ -20,7 +19,7 @@ func Test_WriteFileChecksum(t *testing.T) {
err = file.WriteFileChecksum(nil, original)
require.NoError(t, err)

checksum, err := os.ReadFile(fmt.Sprintf("%s.checksum", original))
checksum, err := os.ReadFile(original + ".checksum")
require.NoError(t, err)

expectedChecksum := []byte("ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73\tfile")
Expand Down
Loading

0 comments on commit a2ebd87

Please sign in to comment.