Files
ghaymah_dev2 ea900387de
ci / test (push) Canceled after 0s
ci / cross-build (amd64, darwin) (push) Canceled after 0s
ci / cross-build (amd64, linux) (push) Canceled after 0s
ci / cross-build (amd64, windows) (push) Canceled after 0s
ci / cross-build (arm64, darwin) (push) Canceled after 0s
ci / cross-build (arm64, linux) (push) Canceled after 0s
ci / cross-build (arm64, windows) (push) Canceled after 0s
Security hardening: dockerignore engine, upload limits, client-side encryption, cross-platform builds
- archive: use Docker's own patternmatcher for .dockerignore/.gitignore/.gyignore + hard secret/VCS/build-output exclusions
- crypto: AES-256-CTR encrypt the source archive before upload (key/IV to gateway via HTTPS)
- deploy: --max-upload / GY_MAX_UPLOAD (default 500 MB)
- Makefile + CI matrix: cross-compile linux/darwin/windows x amd64/arm64
- tests: crypto round-trip + ignore rules
2026-10-24 10:02:34 -04:00

72 lines
1.2 KiB
Go

package source
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"io"
"os"
"testing"
)
func TestEncryptFileRoundTrip(t *testing.T) {
plain := "hello encrypted world — ghaymah 🚀\nsecond line\n"
src, err := os.CreateTemp("", "gy-enc-src")
if err != nil {
t.Fatal(err)
}
defer os.Remove(src.Name())
if _, err := src.WriteString(plain); err != nil {
t.Fatal(err)
}
src.Close()
dst := src.Name() + ".enc"
defer os.Remove(dst)
keyHex, ivHex, err := EncryptFile(src.Name(), dst)
if err != nil {
t.Fatal(err)
}
key, err := hex.DecodeString(keyHex)
if err != nil {
t.Fatal(err)
}
iv, err := hex.DecodeString(ivHex)
if err != nil {
t.Fatal(err)
}
block, err := aes.NewCipher(key)
if err != nil {
t.Fatal(err)
}
stream := cipher.NewCTR(block, iv)
in, err := os.Open(dst)
if err != nil {
t.Fatal(err)
}
defer in.Close()
out, err := os.CreateTemp("", "gy-enc-out")
if err != nil {
t.Fatal(err)
}
defer os.Remove(out.Name())
if _, err := io.Copy(&cipher.StreamWriter{S: stream, W: out}, in); err != nil {
t.Fatal(err)
}
out.Close()
got, err := os.ReadFile(out.Name())
if err != nil {
t.Fatal(err)
}
if string(got) != plain {
t.Fatalf("round trip mismatch:\n got %q\nwant %q", got, plain)
}
}