Skip to content

Commit

Permalink
Merge pull request #9 from tgragnato/main
Browse files Browse the repository at this point in the history
General Project Maintenance: dependency updates and test fixes
  • Loading branch information
JellyBellyDev authored Dec 19, 2023
2 parents 4e25fb7 + c7aad10 commit ab86ed7
Show file tree
Hide file tree
Showing 7 changed files with 1,691 additions and 1,140 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: "1.18.0-rc.1"
go-version: "1.21"
- uses: golangci/golangci-lint-action@v3
with:
version: latest
Expand All @@ -24,9 +24,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: "1.18.0-rc.1"
go-version: "1.21"
- run: go build -v ./...
- run: go test -v ./...
- run: test/test.sh domain.tld
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
.test
.vscode
/inca
/domain.tld.crt
/test.domain.tld.crt
/test.domain.tld.key
/test/crt.pem
/test/key.pem
/server/domain.tld/crt.pem
/server/domain.tld/key.pem
/server/foreign.tld/crt.pem
/server/foreign.tld/key.pem
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine3.14 as builder
FROM golang:alpine3.19 as builder
ENV GOOS=linux
ENV GOARCH=amd64
WORKDIR /workspace
Expand All @@ -8,7 +8,7 @@ RUN go mod download
COPY . .
RUN go build

FROM alpine:3.14
FROM alpine:3.19
WORKDIR /tmp
COPY --from=builder /workspace/inca /usr/sbin/
COPY --from=builder /workspace/server/views /tmp/server/views
Expand Down
450 changes: 187 additions & 263 deletions go.mod

Large diffs are not rendered by default.

2,267 changes: 1,421 additions & 846 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/inca.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/session"
"github.com/gofiber/redirect/v2"
"github.com/gofiber/template/django"
"github.com/gofiber/template/django/v3"
"github.com/immobiliare/inca/provider"
"github.com/immobiliare/inca/server/config"
"github.com/immobiliare/inca/server/helper"
Expand Down
90 changes: 66 additions & 24 deletions server/web_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,26 @@ package server

import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io"
"math/big"
"mime/multipart"
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/gofiber/fiber/v2"
"github.com/immobiliare/inca/util"
"github.com/matryer/is"
)

const (
testingImportDomain = "foreign.tld"
testingImportCrt = `-----BEGIN CERTIFICATE-----
MIIB4zCCAYmgAwIBAgIQOow+W10AzEJL0mVd4zQogTAKBggqhkjOPQQDAjBYMQkw
BwYDVQQGEwAxCTAHBgNVBAgTADEJMAcGA1UEBxMAMQkwBwYDVQQJEwAxCTAHBgNV
BBETADEJMAcGA1UEChMAMRQwEgYDVQQDEwtmb3JlaWduLnRsZDAeFw0yMjEwMDMx
MzE4MTJaFw0yMzExMDQxMzE4MTJaMFgxCTAHBgNVBAYTADEJMAcGA1UECBMAMQkw
BwYDVQQHEwAxCTAHBgNVBAkTADEJMAcGA1UEERMAMQkwBwYDVQQKEwAxFDASBgNV
BAMTC2ZvcmVpZ24udGxkMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVQcXumlM
nSoZEmU+Yd47agAo76oi9lVrPYaGNNw9PPgOSLa7fnPAXQsq9teEZ5hHnEZnpfbo
jRGkwLU8dVbtb6M1MDMwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUF
BwMBMAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSAAwRQIgdcq630BYzpjJwcY8
6K8rMbSu0SjDqRek865/+wQOwKwCIQCqXIKAXlRoFtxX7sMobmZVuNBVz7a/QPpX
rbRKCJDQ9w==
-----END CERTIFICATE-----`
testingImportKey = `-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgC+8lxEP1SSy9P9JO
Ant8Ven+h/a6kICfo/gi++doWBihRANCAARVBxe6aUydKhkSZT5h3jtqACjvqiL2
VWs9hoY03D08+A5Itrt+c8BdCyr214RnmEecRmel9uiNEaTAtTx1Vu1v
-----END PRIVATE KEY-----`
)

func TestServerWebImportView(t *testing.T) {
var (
app = testApp(t)
Expand All @@ -57,10 +43,16 @@ func TestServerWebImportView(t *testing.T) {

func TestServerWebImport(t *testing.T) {
var (
app = testApp(t)
test = is.New(t)
app = testApp(t)
test = is.New(t)
testingImportDomain = "foreign.tld"
)

testingImportCrt, testingImportKey, err := generateKeyPair(testingImportDomain)
if err != nil {
t.Error(err.Error())
}

bodyWriter := &bytes.Buffer{}
writer := multipart.NewWriter(bodyWriter)
crt, err := writer.CreateFormFile("crt", "crt.pem")
Expand Down Expand Up @@ -106,3 +98,53 @@ func TestServerWebImport(t *testing.T) {
test.NoErr(err)
test.Equal(response.StatusCode, fiber.StatusOK)
}

func generateKeyPair(domain string) (publicX509 string, privateX509 string, err error) {
privateKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
if err != nil {
return
}

privBytes, err := x509.MarshalECPrivateKey(privateKey)
if err != nil {
return
}

privateX509 = string(pem.EncodeToMemory(&pem.Block{
Type: "EC PRIVATE KEY",
Bytes: privBytes,
}))

publicKey := &privateKey.PublicKey

subject := pkix.Name{
CommonName: domain,
}

notBefore := time.Now()
notAfter := notBefore.Add(time.Duration(30) * 24 * time.Hour)

certTemplate := x509.Certificate{
Subject: subject,
SerialNumber: big.NewInt(1),
NotBefore: notBefore,
NotAfter: notAfter,
}

certDER, err := x509.CreateCertificate(
rand.Reader,
&certTemplate,
&certTemplate,
publicKey,
privateKey,
)
if err != nil {
return
}

publicX509 = string(pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE",
Bytes: certDER,
}))
return
}

0 comments on commit ab86ed7

Please sign in to comment.