Test in parallel. Remove logging
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -65,32 +64,37 @@ func TestReaderCanReadPDF(t *testing.T) {
|
|||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
ext := filepath.Ext(f.Name())
|
ext := filepath.Ext(f.Name())
|
||||||
if ext != ".pdf" {
|
if ext != ".pdf" {
|
||||||
fmt.Printf("Skipping file %s\n", f.Name())
|
t.Log("Skipping file", f.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
input_file, err := os.Open("../testfiles/" + f.Name())
|
t.Run("", func(st *testing.T) {
|
||||||
if err != nil {
|
st.Parallel()
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
|
||||||
return
|
input_file, err := os.Open("../testfiles/" + f.Name())
|
||||||
}
|
if err != nil {
|
||||||
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
finfo, err := input_file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
input_file.Close()
|
||||||
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
size := finfo.Size()
|
||||||
|
|
||||||
|
_, err = pdf.NewReader(input_file, size)
|
||||||
|
if err != nil {
|
||||||
|
input_file.Close()
|
||||||
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
finfo, err := input_file.Stat()
|
|
||||||
if err != nil {
|
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
})
|
||||||
return
|
|
||||||
}
|
|
||||||
size := finfo.Size()
|
|
||||||
|
|
||||||
_, err = pdf.NewReader(input_file, size)
|
|
||||||
if err != nil {
|
|
||||||
input_file.Close()
|
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
input_file.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,71 +132,78 @@ func TestSignPDF(t *testing.T) {
|
|||||||
certificate_chains := make([][]*x509.Certificate, 0)
|
certificate_chains := make([][]*x509.Certificate, 0)
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
f := f
|
||||||
|
|
||||||
ext := filepath.Ext(f.Name())
|
ext := filepath.Ext(f.Name())
|
||||||
if ext != ".pdf" {
|
if ext != ".pdf" {
|
||||||
fmt.Printf("Skipping file %s\n", f.Name())
|
t.Log("Skipping file", f.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Signing file %s\n", f.Name())
|
t.Run(f.Name(), func(st *testing.T) {
|
||||||
|
st.Parallel()
|
||||||
|
|
||||||
input_file, err := os.Open("../testfiles/" + f.Name())
|
//t.Log("Signing file", f.Name())
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
finfo, err := input_file.Stat()
|
input_file, err := os.Open("../testfiles/" + f.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
input_file.Close()
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
size := finfo.Size()
|
|
||||||
|
|
||||||
rdr, err := pdf.NewReader(input_file, size)
|
finfo, err := input_file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Error("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
size := finfo.Size()
|
||||||
|
|
||||||
outputFile, err := ioutil.TempFile("", "pdfsign_test")
|
rdr, err := pdf.NewReader(input_file, size)
|
||||||
|
if err != nil {
|
||||||
|
input_file.Close()
|
||||||
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = Sign(input_file, outputFile, rdr, size, SignData{
|
outputFile, err := ioutil.TempFile("", "pdfsign_test")
|
||||||
Signature: SignDataSignature{
|
|
||||||
Info: SignDataSignatureInfo{
|
err = Sign(input_file, outputFile, rdr, size, SignData{
|
||||||
Name: "Jeroen Bobbeldijk",
|
Signature: SignDataSignature{
|
||||||
Location: "Rotterdam",
|
Info: SignDataSignatureInfo{
|
||||||
Reason: "Test",
|
Name: "Jeroen Bobbeldijk",
|
||||||
ContactInfo: "Geen",
|
Location: "Rotterdam",
|
||||||
Date: time.Now().Local(),
|
Reason: "Test",
|
||||||
|
ContactInfo: "Geen",
|
||||||
|
Date: time.Now().Local(),
|
||||||
|
},
|
||||||
|
CertType: 2,
|
||||||
|
Approval: false,
|
||||||
},
|
},
|
||||||
CertType: 2,
|
Signer: pkey,
|
||||||
Approval: false,
|
Certificate: cert,
|
||||||
},
|
CertificateChains: certificate_chains,
|
||||||
Signer: pkey,
|
TSA: TSA{
|
||||||
Certificate: cert,
|
URL: "http://aatl-timestamp.globalsign.com/tsa/aohfewat2389535fnasgnlg5m23",
|
||||||
CertificateChains: certificate_chains,
|
},
|
||||||
TSA: TSA{
|
RevocationData: revocation.InfoArchival{},
|
||||||
URL: "http://aatl-timestamp.globalsign.com/tsa/aohfewat2389535fnasgnlg5m23",
|
RevocationFunction: DefaultEmbedRevocationStatusFunction,
|
||||||
},
|
})
|
||||||
RevocationData: revocation.InfoArchival{},
|
|
||||||
RevocationFunction: DefaultEmbedRevocationStatusFunction,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
input_file.Close()
|
||||||
|
os.Remove(outputFile.Name())
|
||||||
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = verify.Verify(outputFile)
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
os.Remove(outputFile.Name())
|
os.Remove(outputFile.Name())
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
if err != nil {
|
||||||
return
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
_, err = verify.Verify(outputFile)
|
|
||||||
input_file.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,13 +10,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"crypto"
|
||||||
|
|
||||||
"bitbucket.org/digitorus/pdf"
|
"bitbucket.org/digitorus/pdf"
|
||||||
"bitbucket.org/digitorus/pdfsign/revocation"
|
"bitbucket.org/digitorus/pdfsign/revocation"
|
||||||
"crypto"
|
|
||||||
"github.com/digitorus/pkcs7"
|
"github.com/digitorus/pkcs7"
|
||||||
"github.com/digitorus/timestamp"
|
"github.com/digitorus/timestamp"
|
||||||
"golang.org/x/crypto/ocsp"
|
"golang.org/x/crypto/ocsp"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
@@ -187,10 +187,10 @@ func Verify(file *os.File) (apiResp *Response, err error) {
|
|||||||
signer.ValidSignature = true
|
signer.ValidSignature = true
|
||||||
signer.TrustedIssuer = false
|
signer.TrustedIssuer = false
|
||||||
}
|
}
|
||||||
log.Println("Invalid sig")
|
//log.Println("Invalid sig")
|
||||||
apiResp.Error = fmt.Sprintln("Failed to verify signature:", err)
|
apiResp.Error = fmt.Sprintln("Failed to verify signature:", err)
|
||||||
} else {
|
} else {
|
||||||
log.Println("Valid sig")
|
//log.Println("Valid sig")
|
||||||
signer.ValidSignature = true
|
signer.ValidSignature = true
|
||||||
signer.TrustedIssuer = true
|
signer.TrustedIssuer = true
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user