-
Notifications
You must be signed in to change notification settings - Fork 7
Regular validator updates MTA-STS-dependent policies #217
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2a8d29
Regular validator goes through MTA-STS-dependent policies
sydneyli 321f55e
fix golint path
sydneyli 7ebf3cd
Merge branch 'master' into mta-sts-upgrade
sydneyli 6c8b255
Merge branch 'master' into mta-sts-upgrade
sydneyli fccb654
Revert name changes from GetDomain => GetDomainInState
sydneyli 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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import ( | |
| "net/http" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/EFForg/starttls-backend/models" | ||
| ) | ||
|
|
||
| // policyURL is the default URL from which to fetch the policy JSON. | ||
|
|
@@ -80,14 +82,23 @@ func (l *UpdatedList) DomainsToValidate() ([]string, error) { | |
| return domains, nil | ||
| } | ||
|
|
||
| // HostnamesForDomain [interface Validator] retrieves the hostname policy for | ||
| // GetDomain [interface Validator] retrieves the domain object for | ||
| // a particular domain. | ||
| func (l *UpdatedList) HostnamesForDomain(domain string) ([]string, error) { | ||
| func (l *UpdatedList) GetDomain(domain string) (models.Domain, error) { | ||
| policy, err := l.Get(domain) | ||
| if err != nil { | ||
| return []string{}, err | ||
| return models.Domain{}, err | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this reuse of the domain model! |
||
| } | ||
| domainObj := models.Domain{ | ||
| Name: domain, | ||
| MXs: policy.MXs, | ||
| } | ||
| if policy.Mode == "enforce" { | ||
| domainObj.State = models.StateEnforce | ||
| } else if policy.Mode == "testing" { | ||
| domainObj.State = models.StateTesting | ||
| } | ||
| return policy.MXs, nil | ||
| return domainObj, nil | ||
| } | ||
|
|
||
| // Get safely reads from the underlying policy list and returns a TLSPolicy for a domain | ||
|
|
||
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
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,27 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "reflect" | ||
| ) | ||
|
|
||
| // ListsEqual checks that two lists have the same elements, | ||
| // regardless of order. | ||
| func ListsEqual(x []string, y []string) bool { | ||
| // Transform each list into a histogram | ||
| xMap := make(map[string]uint) | ||
| yMap := make(map[string]uint) | ||
| for _, element := range x { | ||
| if _, ok := xMap[element]; !ok { | ||
| xMap[element] = 0 | ||
| } | ||
| xMap[element]++ | ||
| } | ||
| for _, element := range y { | ||
| if _, ok := yMap[element]; !ok { | ||
| yMap[element] = 0 | ||
| } | ||
| yMap[element]++ | ||
| } | ||
| // Compare the histogram maps | ||
| return reflect.DeepEqual(xMap, yMap) | ||
| } |
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,29 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestListsEqual(t *testing.T) { | ||
| testCases := []struct { | ||
| x []string | ||
| y []string | ||
| expected bool | ||
| }{ | ||
| {[]string{}, []string{}, true}, | ||
| {[]string{"a"}, []string{}, false}, | ||
| {[]string{"a"}, []string{"a"}, true}, | ||
| {[]string{"a", "a"}, []string{"a"}, false}, | ||
| {[]string{"a", "b", "c"}, []string{"a", "b", "c"}, true}, | ||
| {[]string{"b", "a", "c"}, []string{"a", "b", "c"}, true}, | ||
| {[]string{"b", "a", "b", "c"}, []string{"a", "b", "c"}, false}, | ||
| {[]string{"b", "a", "b", "c"}, []string{"a", "b", "a", "c"}, false}, | ||
| {[]string{"a", "a", "b", "c"}, []string{"a", "b", "a", "c"}, true}, | ||
| } | ||
| for _, testCase := range testCases { | ||
| got := ListsEqual(testCase.x, testCase.y) | ||
| if got != testCase.expected { | ||
| t.Errorf("Compared %v and %v, expected %v, got %v", testCase.x, testCase.y, testCase.expected, got) | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
This will update the policy and status for all matching domains - there could but multiple (domain, status) pairs returned. Seems like updating
statusfor all of them could cause a collision.