Skip to content

Commit 9287d7e

Browse files
Check a CT submission happens during integration tests
1 parent c9e8d1e commit 9287d7e

File tree

2 files changed

+58
-26
lines changed

2 files changed

+58
-26
lines changed

test/amqp-integration-test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import subprocess
88
import sys
99
import tempfile
10+
import urllib2
1011

1112
import startservers
1213

1314

1415
class ExitStatus:
15-
OK, PythonFailure, NodeFailure, Error, OCSPFailure = range(5)
16+
OK, PythonFailure, NodeFailure, Error, OCSPFailure, CTFailure = range(6)
1617

1718

1819
class ProcInfo:
@@ -62,6 +63,13 @@ def verify_ocsp_revoked(certFile, url):
6263
die(ExitStatus.OCSPFailure)
6364
pass
6465

66+
def verify_ct_submission(expectedSubmissions, url):
67+
resp = urllib2.urlopen(url)
68+
submissionStr = resp.read()
69+
if int(submissionStr) != expectedSubmissions:
70+
print "Expected %d submissions, found %d" % (expectedSubmissions, int(submissionStr))
71+
die(ExitStatus.CTFailure)
72+
6573
def run_node_test():
6674
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6775
try:
@@ -91,6 +99,7 @@ def run_node_test():
9199
# Also verify that the static OCSP responder, which answers with a
92100
# pre-signed, long-lived response for the CA cert, also works.
93101
verify_ocsp_good("../test-ca.der", issuer_ocsp_url)
102+
verify_ct_submission(1, "http://localhost:4500/submissions")
94103

95104
if subprocess.Popen('''
96105
node revoke.js %s %s http://localhost:4000/acme/revoke-cert

test/ct-test-srv/main.go

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,70 @@ package main
1010

1111
import (
1212
"encoding/json"
13+
"fmt"
1314
"io/ioutil"
1415
"log"
1516
"net/http"
17+
"sync/atomic"
1618
)
1719

1820
type ctSubmissionRequest struct {
1921
Chain []string `json:"chain"`
2022
}
2123

22-
func handler(w http.ResponseWriter, r *http.Request) {
23-
if r.Method != "POST" || r.URL.Path != "/ct/v1/add-chain" {
24+
type integrationSrv struct {
25+
submissions int64
26+
}
27+
28+
func (is *integrationSrv) handler(w http.ResponseWriter, r *http.Request) {
29+
switch r.URL.Path {
30+
case "/ct/v1/add-chain":
31+
if r.Method != "POST" {
32+
http.NotFound(w, r)
33+
return
34+
}
35+
bodyBytes, err := ioutil.ReadAll(r.Body)
36+
if err != nil {
37+
http.Error(w, err.Error(), http.StatusBadRequest)
38+
}
39+
40+
var addChainReq ctSubmissionRequest
41+
err = json.Unmarshal(bodyBytes, &addChainReq)
42+
if err != nil {
43+
http.Error(w, err.Error(), http.StatusBadRequest)
44+
}
45+
46+
w.WriteHeader(http.StatusOK)
47+
// id is a sha256 of a random EC key. Generate your own with:
48+
// openssl ecparam -name prime256v1 -genkey -outform der | openssl sha256 -binary | base64
49+
w.Write([]byte(`{
50+
"sct_version": 0,
51+
"id": "8fjM8cvLPOhzCFwI62IYJhjkOcvWFLx1dMJbs0uhxJU=",
52+
"timestamp": 1442400000,
53+
"extensions": "",
54+
"signature": "BAMARzBFAiBB5wKED8KqKhADT37n0y28fZIPiGbCfZRVKq0wNo0hrwIhAOIa2tPBF/rB1y30Y/ROh4LBmJ0mItAbTWy8XZKh7Wcp"
55+
}`))
56+
atomic.AddInt64(&is.submissions, 1)
57+
case "/submissions":
58+
if r.Method != "GET" {
59+
http.NotFound(w, r)
60+
return
61+
}
62+
63+
submissions := atomic.LoadInt64(&is.submissions)
64+
w.WriteHeader(http.StatusOK)
65+
w.Write([]byte(fmt.Sprintf("%d", submissions)))
66+
default:
2467
http.NotFound(w, r)
2568
return
2669
}
27-
bodyBytes, err := ioutil.ReadAll(r.Body)
28-
if err != nil {
29-
http.Error(w, err.Error(), http.StatusBadRequest)
30-
}
31-
32-
var addChainReq ctSubmissionRequest
33-
err = json.Unmarshal(bodyBytes, &addChainReq)
34-
if err != nil {
35-
http.Error(w, err.Error(), http.StatusBadRequest)
36-
}
37-
38-
w.WriteHeader(http.StatusOK)
39-
// id is a sha256 of a random EC key. Generate your own with:
40-
// openssl ecparam -name prime256v1 -genkey -outform der | openssl sha256 -binary | base64
41-
w.Write([]byte(`{
42-
"sct_version": 0,
43-
"id": "8fjM8cvLPOhzCFwI62IYJhjkOcvWFLx1dMJbs0uhxJU=",
44-
"timestamp": 1442400000,
45-
"extensions": "",
46-
"signature": "BAMARzBFAiBB5wKED8KqKhADT37n0y28fZIPiGbCfZRVKq0wNo0hrwIhAOIa2tPBF/rB1y30Y/ROh4LBmJ0mItAbTWy8XZKh7Wcp"
47-
}`))
4870
}
4971

5072
func main() {
73+
is := integrationSrv{}
5174
s := &http.Server{
52-
Addr: ":4500",
53-
Handler: http.HandlerFunc(handler),
75+
Addr: "localhost:4500",
76+
Handler: http.HandlerFunc(is.handler),
5477
}
5578
log.Fatal(s.ListenAndServe())
5679
}

0 commit comments

Comments
 (0)