Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Get Domains by PolicyType functions #221

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions api/get_domains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package api

import (
"github.com/chromium/hstspreload/chromium/preloadlist"
)

// GetDomainsByPolicyType returns a list of entries from the preloadlist that have the pt policy type
func GetDomainsByPolicyType(list preloadlist.PreloadList, pt preloadlist.PolicyType) []preloadlist.Entry {
var domains []preloadlist.Entry

for _, entry := range list.Entries {
if entry.Policy == pt {
domains = append(domains, entry)
}
}

return domains
}
39 changes: 39 additions & 0 deletions api/get_domains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package api

import (
"reflect"
"testing"

"github.com/chromium/hstspreload/chromium/preloadlist"
)

var TestPreloadList = preloadlist.PreloadList{Entries: []preloadlist.Entry{
{Name: "garron.net", Mode: "force-https", IncludeSubDomains: true, Policy: "bulk-18-weeks"},
{Name: "example.com", Mode: "force-https", IncludeSubDomains: false, Policy: "bulk-18-weeks"},
{Name: "gmail.com", Mode: "force-https", IncludeSubDomains: false, Policy: ""},
{Name: "google.com", Mode: "", IncludeSubDomains: false, Policy: "custom"},
{Name: "pinned.badssl.com", Mode: "", IncludeSubDomains: false, Policy: "bulk-1-year"}},
}

func TestGetDomainsByPolicyType(t *testing.T) {
domains18weeks := GetDomainsByPolicyType(TestPreloadList, preloadlist.Bulk18Weeks)
domains1year := GetDomainsByPolicyType(TestPreloadList, preloadlist.Bulk1Year)

var expected18weeks = []preloadlist.Entry{
{Name: "garron.net", Mode: "force-https", IncludeSubDomains: true, Policy: "bulk-18-weeks"},
{Name: "example.com", Mode: "force-https", IncludeSubDomains: false, Policy: "bulk-18-weeks"},
}

var expected1year = []preloadlist.Entry{
{Name: "pinned.badssl.com", Mode: "", IncludeSubDomains: false, Policy: "bulk-1-year"},
}

if !reflect.DeepEqual(domains18weeks, expected18weeks) {
t.Errorf("bulk-18-week policy domains does not match expected")
}

if !reflect.DeepEqual(domains1year, expected1year) {
t.Errorf("bulk-1-year policy domains does not match expected")
}

}
29 changes: 10 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ module github.com/chromium/hstspreload.org
go 1.15

require (
cloud.google.com/go/datastore v1.8.0
github.com/chromium/hstspreload v0.0.0-20220201002458-2f7d9e63b849
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48
google.golang.org/api v0.91.0
google.golang.org/grpc v1.48.0
cloud.google.com/go/datastore v1.11.0
github.com/chromium/hstspreload v0.0.0-20230620174236-bb638f02e21f
golang.org/x/net v0.11.0
google.golang.org/api v0.128.0
google.golang.org/grpc v1.56.0
)

require (
cloud.google.com/go v0.102.1 // indirect
cloud.google.com/go/compute v1.7.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/compute v1.20.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
Loading