Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions test/ct-test-srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type ctSubmissionRequest struct {

type integrationSrv struct {
sync.Mutex
submissions map[string]int64
submissions map[string]int64
submissionsCap int
// Hostnames where we refuse to provide an SCT. This is to exercise the code
// path where all CT servers fail.
rejectHosts map[string]bool
Expand Down Expand Up @@ -156,9 +157,7 @@ func (is *integrationSrv) addChainOrPre(w http.ResponseWriter, r *http.Request,
}
}

is.Lock()
is.submissions[hostnames]++
is.Unlock()
is.addSubmission(hostnames)

if is.flakinessRate != 0 && rand.IntN(100) < is.flakinessRate {
time.Sleep(10 * time.Second)
Expand All @@ -168,6 +167,16 @@ func (is *integrationSrv) addChainOrPre(w http.ResponseWriter, r *http.Request,
w.Write(publisher.CreateTestingSignedSCT(addChainReq.Chain, is.key, precert, time.Now()))
}

func (is *integrationSrv) addSubmission(hostnames string) {
is.Lock()
defer is.Unlock()

_, ok := is.submissions[hostnames]
if ok || len(is.submissions) < is.submissionsCap {
is.submissions[hostnames]++
}
Comment on lines +174 to +177
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the idea. I don't think evicting or reset is useful for integration tests

}

func (is *integrationSrv) getSubmissions(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.NotFound(w, r)
Expand Down Expand Up @@ -199,6 +208,9 @@ type Personality struct {
// FlakinessRate is an integer between 0-100 that controls how often the log
// "flakes", i.e. fails to respond in a reasonable time frame.
FlakinessRate int
// SubmissionsCap limits the number of hostnames we track. Defaults to 100.
// After that many entries, new hostnames won't be counted in /submissions.
SubmissionsCap int
}

func runPersonality(p Personality) {
Expand All @@ -210,12 +222,17 @@ func runPersonality(p Personality) {
if err != nil {
log.Fatal(err)
}
cap := p.SubmissionsCap
if cap == 0 {
cap = 100
Comment on lines +225 to +227
}
is := integrationSrv{
key: key,
flakinessRate: p.FlakinessRate,
submissions: make(map[string]int64),
rejectHosts: make(map[string]bool),
userAgent: p.UserAgent,
key: key,
flakinessRate: p.FlakinessRate,
submissions: make(map[string]int64),
submissionsCap: cap,
rejectHosts: make(map[string]bool),
userAgent: p.UserAgent,
}
m := http.NewServeMux()
m.HandleFunc("/submissions", is.getSubmissions)
Expand Down