-
Notifications
You must be signed in to change notification settings - Fork 96
Added Get Domains by PolicyType functions #221
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
Open
tKabiawu
wants to merge
10
commits into
chromium:main
Choose a base branch
from
tKabiawu:gatherList
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bbd09b8
Created 2 slices to hold domains of the 18 week and 1 year policy types
tKabiawu 8ed2aca
Created 2 slices to hold domains of the 18 week and 1 year policy types
tKabiawu 9f389b6
Created 2 slices to hold domains of the 18 week and 1 year policy types
tKabiawu 57c6c10
Added a gatherLists function and tests
tKabiawu 8826a0f
Fixed a formatting issue
tKabiawu 1c2924c
Changed Names of Functions, Simplified Tes
tKabiawu 914f9c0
Fixed a little spelling mistake
tKabiawu f9ea096
Changed return type of function to be preloadlist.Entry
tKabiawu 00b9a18
Made two different functions to get the two types of preloadlist entr…
tKabiawu 5848817
simplified functions to remove code duplication
tKabiawu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "github.com/chromium/hstspreload/chromium/preloadlist" | ||
| ) | ||
|
|
||
| type PolicyType int | ||
|
|
||
| const ( | ||
| bulk18Week PolicyType = iota | ||
| bulk1Year | ||
| ) | ||
|
|
||
| func (pt PolicyType) String() string { | ||
| return []string{"bulk-18-weeks", "bulk-1-year"}[pt] | ||
| } | ||
|
|
||
| // GetBulk18Weeks reuturns a list of entries from the preloadlist that have "bulk-18-weeks" policy type | ||
| func GetBulk18WeeksDomains(list preloadlist.PreloadList) []preloadlist.Entry { | ||
| var domains []preloadlist.Entry | ||
|
|
||
| for _, entry := range list.Entries { | ||
| if entry.Policy == bulk18Week.String() { | ||
| domains = append(domains, entry) | ||
| } | ||
| } | ||
|
|
||
| return domains | ||
| } | ||
|
|
||
| // GetBulk1Year returns a list of entries from the preloadlist that have "bulk-1-year" policy type | ||
| func GetBulk1YearDomains(list preloadlist.PreloadList) []preloadlist.Entry { | ||
| var domains []preloadlist.Entry | ||
|
|
||
| for _, entry := range list.Entries { | ||
| if entry.Policy == bulk1Year.String() { | ||
| domains = append(domains, entry) | ||
| } | ||
| } | ||
|
|
||
| return domains | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 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"}}, | ||
| } | ||
|
|
||
| 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"}, | ||
| } | ||
|
|
||
| func TestGetBulk18WeeksDomains(t *testing.T) { | ||
| domains18weeks := GetBulk18WeeksDomains(TestPreloadList) | ||
|
|
||
| if !reflect.DeepEqual(domains18weeks, expected18weeks) { | ||
| t.Errorf("bulk18week domains does not match expected") | ||
| } | ||
| } | ||
|
|
||
| func TestGetBulk1YearDomains(t *testing.T) { | ||
| domains1year := GetBulk1YearDomains(TestPreloadList) | ||
|
|
||
| if !reflect.DeepEqual(domains1year, expected1year) { | ||
| t.Errorf("bulk1year domains does not match") | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PolicyTypecan be a string and then the slice isn't needed. IfPolicyTypeis defined to be a string, then thepreloadlist.Entrystruct can have its Policy field be of typePolicyType. See the preload status field inDomainStateas an example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done