Skip to content

Commit 73b281f

Browse files
committed
Integration tests
1 parent 7fd12f4 commit 73b281f

31 files changed

Lines changed: 1298 additions & 38 deletions

.flake8

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Set up Go
14+
uses: actions/setup-go@v5
15+
with:
16+
go-version: "1.22"
17+
18+
- name: Run unit tests
19+
run: go test -v ./...
20+
21+
integration-sqlite:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: "1.22"
30+
31+
- name: Build cryptctl
32+
run: go build -o cryptctl ./cmd/cryptctl/
33+
34+
- name: Generate encryption key
35+
run: ./cryptctl gen-key > /tmp/test_key.txt
36+
37+
- name: Run SQLite integration tests
38+
run: ./cryptctl integration-test -db sqlite -key-file /tmp/test_key.txt
39+
40+
integration-postgres:
41+
runs-on: ubuntu-latest
42+
services:
43+
postgres:
44+
image: postgres:15
45+
env:
46+
POSTGRES_USER: crypt
47+
POSTGRES_PASSWORD: crypt_test_password
48+
POSTGRES_DB: crypt_test
49+
ports:
50+
- 5432:5432
51+
options: >-
52+
--health-cmd pg_isready
53+
--health-interval 10s
54+
--health-timeout 5s
55+
--health-retries 5
56+
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- name: Set up Go
61+
uses: actions/setup-go@v5
62+
with:
63+
go-version: "1.22"
64+
65+
- name: Build cryptctl
66+
run: go build -o cryptctl ./cmd/cryptctl/
67+
68+
- name: Generate encryption key
69+
run: ./cryptctl gen-key > /tmp/test_key.txt
70+
71+
- name: Run PostgreSQL integration tests
72+
run: |
73+
./cryptctl integration-test \
74+
-db postgres \
75+
-db-url "postgres://crypt:crypt_test_password@localhost:5432/crypt_test?sslmode=disable" \
76+
-key-file /tmp/test_key.txt

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ keyset
1010
*.db
1111

1212
.vscode
13-
.gocache/*
13+
.gocache/*
14+
15+
cryptctl
16+
crypt-server
17+
18+
.claude/settings.local.json

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
VERSION := $(shell cat VERSION)
2+
LDFLAGS := -ldflags "-X crypt-server/internal/app.Version=$(VERSION)"
3+
4+
.PHONY: build clean test
5+
6+
build:
7+
go build $(LDFLAGS) -o crypt-server ./cmd/crypt-server
8+
9+
test:
10+
go test ./...
11+
12+
clean:
13+
rm -f crypt-server

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2012-2016 Graham Gilbert
1+
Copyright 2012-2026 Graham Gilbert
22
Licensed under the Apache License, Version 2.0 (the "License");
33
you may not use this file except in compliance with the License.
44
You may obtain a copy of the License at

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ All settings that would be entered into `settings.py` can also be passed into th
6868

6969
- `EMAIL_SENDER` - The email address to send emaiil notifications from when secrets are requests and approved. Ensure this is verified if you are using SES. Does nothing unless `SEND_EMAIIL` is True.
7070

71-
- `APPROVE_OWN` - By default, users with approval permissons can approve their own key requests. By setting this to False in settings.py (or by using the `APPROVE_OWN` environment variable with Docker), users cannot approve their own requests.
71+
- `APPROVE_OWN` - By default, users with approval permissions cannot approve their own key requests. Set this to `true` to allow users to approve their own requests.
7272

7373
- `ALL_APPROVE` - By default, users need to be explicitly given approval permissions to approve key retrieval requests. By setting this to True in `settings.py`, all users are given this permission when they log in.
7474

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0.0

cmd/crypt-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func main() {
9494
logger.Fatalf("invalid session configuration: %v", err)
9595
}
9696
settings := app.Settings{
97-
ApproveOwn: envBool("APPROVE_OWN", true),
97+
ApproveOwn: envBool("APPROVE_OWN", false),
9898
AllApprove: envBool("ALL_APPROVE", false),
9999
SessionTTL: sessionTTL,
100100
CookieSecure: envBool("SESSION_COOKIE_SECURE", false),

cmd/cryptctl/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ func main() {
7676
fmt.Fprintln(flag.CommandLine.Output(), "Usage: cryptctl <command>")
7777
fmt.Fprintln(flag.CommandLine.Output(), "")
7878
fmt.Fprintln(flag.CommandLine.Output(), "Commands:")
79-
fmt.Fprintln(flag.CommandLine.Output(), " gen-key Generate a base64-encoded 32-byte FIELD_ENCRYPTION_KEY")
80-
fmt.Fprintln(flag.CommandLine.Output(), " import-fixture Convert Django JSON fixtures into an encrypted migration export")
79+
fmt.Fprintln(flag.CommandLine.Output(), " gen-key Generate a base64-encoded 32-byte FIELD_ENCRYPTION_KEY")
80+
fmt.Fprintln(flag.CommandLine.Output(), " import-fixture Convert Django JSON fixtures into an encrypted migration export")
81+
fmt.Fprintln(flag.CommandLine.Output(), " integration-test Run integration tests against a database")
8182
}
8283
flag.Parse()
8384

@@ -97,6 +98,11 @@ func main() {
9798
fmt.Fprintln(os.Stderr, err)
9899
os.Exit(1)
99100
}
101+
case "integration-test":
102+
if err := runIntegrationTest(os.Args[2:], os.Stdout); err != nil {
103+
fmt.Fprintln(os.Stderr, err)
104+
os.Exit(1)
105+
}
100106
default:
101107
fmt.Fprintf(os.Stderr, "unknown command: %s\n", flag.Arg(0))
102108
flag.Usage()

0 commit comments

Comments
 (0)