Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions ctpolicy/loglist/loglist.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func usableForPurpose(s loglist3.LogStatus, p purpose) bool {
return false
}

// isTestLog returns true if the log type is test is "test" or "monitoring_only".
// The schema documents a third option, "prod", which does not currently appear in Google's lists.
func isTestLog(log Log) bool {
return log.Type == "test" || log.Type == "monitoring_only"
}

// New returns a LogList of all operators and all logs parsed from the file at
// the given path. The file must conform to the JSON Schema published by Google:
// https://www.gstatic.com/ct/log_list/v3/log_list_schema.json
Expand Down Expand Up @@ -186,10 +192,13 @@ func (ll List) forPurpose(p purpose, submitToTestLogs bool) (List, error) {
// interprets this as "UndefinedLogStatus", which causes usableForPurpose()
// to return false. To account for this, we skip this check for test logs.
for _, log := range ll {
if log.Type == "test" && !submitToTestLogs {
// Only consider test logs if we are submitting to test logs:
if isTestLog(log) && !submitToTestLogs {
continue
}
if log.Type != "test" && !usableForPurpose(log.State, p) {
// Check the log is usable for a purpose.
// But test logs aren't ever marked Usable.
if !isTestLog(log) && !usableForPurpose(log.State, p) {
continue
}
res = append(res, log)
Expand Down
2 changes: 2 additions & 0 deletions ctpolicy/loglist/loglist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestForPurpose(t *testing.T) {
Log{Name: "Log A1", Operator: "A", State: loglist3.UsableLogStatus},
Log{Name: "Log B1", Operator: "B", State: loglist3.UsableLogStatus},
Log{Name: "Log T1", Operator: "T", Type: "test", State: loglist3.UndefinedLogStatus},
Log{Name: "Log M1", Operator: "M", Type: "monitoring_only", State: loglist3.UndefinedLogStatus},
}
expected = List{
Log{Name: "Log A1", Operator: "A", State: loglist3.UsableLogStatus},
Expand All @@ -108,6 +109,7 @@ func TestForPurpose(t *testing.T) {
Log{Name: "Log A1", Operator: "A", State: loglist3.UsableLogStatus},
Log{Name: "Log B1", Operator: "B", State: loglist3.UsableLogStatus},
Log{Name: "Log T1", Operator: "T", Type: "test", State: loglist3.UndefinedLogStatus},
Log{Name: "Log M1", Operator: "M", Type: "monitoring_only", State: loglist3.UndefinedLogStatus},
}
actual, err = input.forPurpose(Issuance, true)
test.AssertNotError(t, err, "should have two acceptable logs with submitToTestLogs=[true]")
Expand Down