-
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 5 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,22 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "github.com/chromium/hstspreload/chromium/preloadlist" | ||
| ) | ||
|
|
||
| // gatherLists returns a list of domains filtered by Policy types "bulk-18-weeks" and "bulk-1-year" | ||
| func gatherLists(list preloadlist.PreloadList) ([]string, []string) { | ||
| var domains18weeks []string | ||
| var domains1year []string | ||
|
|
||
| for _, entry := range list.Entries { | ||
| if entry.Policy == "bulk-18-weeks" { | ||
| domains18weeks = append(domains18weeks, entry.Name) | ||
| } | ||
| if entry.Policy == "bulk-1-year" { | ||
| domains1year = append(domains1year, entry.Name) | ||
| } | ||
| } | ||
|
|
||
| return domains18weeks, domains1year | ||
| } | ||
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,31 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/chromium/hstspreload/chromium/preloadlist" | ||
| ) | ||
|
|
||
| func TestGatherLists(t *testing.T) { | ||
| 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"}}, | ||
| } | ||
|
|
||
| expected18weeks := []string{"garron.net", "example.com"} | ||
| expected1year := []string{"pinned.badssl.com"} | ||
|
|
||
| domains18weeks, domains1year := gatherLists(TestPreloadList) | ||
|
|
||
| if !reflect.DeepEqual(domains18weeks, expected18weeks) { | ||
| t.Errorf("bulk18week domains does not match expected") | ||
| } | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I can see that this might be useful, but as implemented this is vague and ambiguous in several ways:
Also:
hstspreload.orgpackage rather thanhstspreload?I also don't see a stated motivation for this PR. If the goal is to be able to get subsets of the list, would it make just as much sense to provide filters for individual states rather than gathering some subsets at once?
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi Lucas,
Thanks so much for your comments they were very helpful. I'm currently a step intern working under @nharper and @carlosjoan91, and the project we are working on revolves around automating processes concerning the hsts preload list. I have attempted to make changes to the code that adheres to some of your suggestions by providing functions that filter for individual states rather than gathering some subsets at once, returning entries instead of strings (thereby annotating the return type), capitalizing the function so that it is exportable, and defining constants as enums. Initially, I chose to return just the domain strings rather than the entries because I thought we only needed the domain name to check whether the domain is preloadable with the PreloadableDomain() function. However, I forgot that to change the status of a domain, you also need the value of the includeSubDomains field, which led me to choose to return the entire entry. Moreover, my understanding as the reason this is implemented in the
hstspreload.orgpackage instead of thehstspreloadis because we plan to use a task scheduling tool that will call the endpoint at regular intervals.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.
Ah, thanks, I was missing the context! Happy to see work on this project, but I'm glad to leave you in @nharper and @carlosjoan91's capable hands for an actual review. 😄