Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
notarize: tests for parselog
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Nov 6, 2019
1 parent 4c90bcd commit 184f266
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
44 changes: 44 additions & 0 deletions notarize/log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package notarize

import (
"os"
"path/filepath"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/sebdah/goldie"
"github.com/stretchr/testify/require"
)

func init() {
goldie.FixtureDir = "testdata"
spew.Config.DisablePointerAddresses = true
}

func TestParseFile(t *testing.T) {
f, err := os.Open("testdata")
require.NoError(t, err)
defer f.Close()

fis, err := f.Readdir(-1)
require.NoError(t, err)
for _, fi := range fis {
if fi.IsDir() {
continue
}

if filepath.Ext(fi.Name()) == ".golden" {
continue
}

t.Run(fi.Name(), func(t *testing.T) {
f, err := os.Open(filepath.Join("testdata", fi.Name()))
require.NoError(t, err)
defer f.Close()

log, err := ParseLog(f)
require.NoError(t, err)
goldie.Assert(t, fi.Name(), []byte(spew.Sdump(log)))
})
}
}
37 changes: 37 additions & 0 deletions notarize/testdata/log_zip_failure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"logFormatVersion": 1,
"jobId": "4ba7c420-7444-44bc-a190-1bd4bad97b13",
"status": "Invalid",
"statusSummary": "Archive contains critical validation errors",
"statusCode": 4000,
"archiveFilename": "gon.zip",
"uploadDate": "2019-11-06T00:54:22Z",
"sha256": "c109f26d378fbf1efadc8987fdab79d2ce63155e8941823d4d11a907152e11a5",
"ticketContents": null,
"issues": [
{
"severity": "error",
"code": null,
"path": "gon.zip/foo",
"message": "The binary is not signed.",
"docUrl": null,
"architecture": "x86_64"
},
{
"severity": "error",
"code": null,
"path": "gon.zip/foo",
"message": "The signature does not include a secure timestamp.",
"docUrl": null,
"architecture": "x86_64"
},
{
"severity": "error",
"code": null,
"path": "gon.zip/foo",
"message": "The executable does not have the hardened runtime enabled.",
"docUrl": null,
"architecture": "x86_64"
}
]
}
27 changes: 27 additions & 0 deletions notarize/testdata/log_zip_failure.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(*notarize.Log)({
JobId: (string) (len=36) "4ba7c420-7444-44bc-a190-1bd4bad97b13",
Status: (string) (len=7) "Invalid",
StatusSummary: (string) (len=43) "Archive contains critical validation errors",
StatusCode: (int) 4000,
ArchiveFilename: (string) (len=7) "gon.zip",
UploadDate: (string) (len=20) "2019-11-06T00:54:22Z",
SHA256: (string) (len=64) "c109f26d378fbf1efadc8987fdab79d2ce63155e8941823d4d11a907152e11a5",
Issues: ([]notarize.LogIssue) (len=3 cap=4) {
(notarize.LogIssue) {
Severity: (string) (len=5) "error",
Path: (string) (len=11) "gon.zip/foo",
Message: (string) (len=25) "The binary is not signed."
},
(notarize.LogIssue) {
Severity: (string) (len=5) "error",
Path: (string) (len=11) "gon.zip/foo",
Message: (string) (len=50) "The signature does not include a secure timestamp."
},
(notarize.LogIssue) {
Severity: (string) (len=5) "error",
Path: (string) (len=11) "gon.zip/foo",
Message: (string) (len=58) "The executable does not have the hardened runtime enabled."
}
},
TicketContents: ([]notarize.LogTicketContent) <nil>
})
19 changes: 19 additions & 0 deletions notarize/testdata/log_zip_success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"logFormatVersion": 1,
"jobId": "3382aa04-e417-46a0-b1b4-42eebf85906c",
"status": "Accepted",
"statusSummary": "Ready for distribution",
"statusCode": 0,
"archiveFilename": "gon.zip",
"uploadDate": "2019-11-06T00:51:10Z",
"sha256": "1070be725b5b0c89b8dad699a9080a3bf5809fe68bfe8f84d6ff4a282d661fd1",
"ticketContents": [
{
"path": "gon.zip/foo",
"digestAlgorithm": "SHA-256",
"cdhash": "b7049085e21423f102d6119bca93d57ebd903289",
"arch": "x86_64"
}
],
"issues": null
}
18 changes: 18 additions & 0 deletions notarize/testdata/log_zip_success.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(*notarize.Log)({
JobId: (string) (len=36) "3382aa04-e417-46a0-b1b4-42eebf85906c",
Status: (string) (len=8) "Accepted",
StatusSummary: (string) (len=22) "Ready for distribution",
StatusCode: (int) 0,
ArchiveFilename: (string) (len=7) "gon.zip",
UploadDate: (string) (len=20) "2019-11-06T00:51:10Z",
SHA256: (string) (len=64) "1070be725b5b0c89b8dad699a9080a3bf5809fe68bfe8f84d6ff4a282d661fd1",
Issues: ([]notarize.LogIssue) <nil>,
TicketContents: ([]notarize.LogTicketContent) (len=1 cap=4) {
(notarize.LogTicketContent) {
Path: (string) (len=11) "gon.zip/foo",
DigestAlgorithm: (string) (len=7) "SHA-256",
CDHash: (string) (len=40) "b7049085e21423f102d6119bca93d57ebd903289",
Arch: (string) (len=6) "x86_64"
}
}
})

0 comments on commit 184f266

Please sign in to comment.