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,20 +64,23 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("", func(st *testing.T) {
|
||||||
|
st.Parallel()
|
||||||
|
|
||||||
input_file, err := os.Open("../testfiles/" + f.Name())
|
input_file, err := os.Open("../testfiles/" + f.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
finfo, err := input_file.Stat()
|
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.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
size := finfo.Size()
|
size := finfo.Size()
|
||||||
@@ -86,11 +88,13 @@ func TestReaderCanReadPDF(t *testing.T) {
|
|||||||
_, err = pdf.NewReader(input_file, size)
|
_, err = pdf.NewReader(input_file, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,24 +132,29 @@ 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()
|
||||||
|
|
||||||
|
//t.Log("Signing file", f.Name())
|
||||||
|
|
||||||
input_file, err := os.Open("../testfiles/" + f.Name())
|
input_file, err := os.Open("../testfiles/" + f.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
finfo, err := input_file.Stat()
|
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()
|
size := finfo.Size()
|
||||||
@@ -153,7 +162,7 @@ func TestSignPDF(t *testing.T) {
|
|||||||
rdr, err := pdf.NewReader(input_file, size)
|
rdr, err := pdf.NewReader(input_file, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,15 +193,17 @@ func TestSignPDF(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
os.Remove(outputFile.Name())
|
os.Remove(outputFile.Name())
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.Errorf("%s: %s", f.Name(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = verify.Verify(outputFile)
|
_, err = verify.Verify(outputFile)
|
||||||
input_file.Close()
|
input_file.Close()
|
||||||
|
os.Remove(outputFile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: %s", f.Name(), err.Error())
|
st.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