Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move chromiumpreload to chromium/preloadlist and implement reading fr…
…om file or arbitrary URL.
- Loading branch information
Showing
6 changed files
with
192 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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,117 @@ | ||
package preloadlist | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestIndexing(t *testing.T) { | ||
list := PreloadList{ | ||
Entries: []Entry{ | ||
{ | ||
Name: "garron.NET", | ||
Mode: "ForceHTTPS", | ||
IncludeSubDomains: true, | ||
}, | ||
{ | ||
Name: "example.com", | ||
Mode: "", | ||
IncludeSubDomains: false, | ||
}, | ||
}, | ||
} | ||
|
||
idx := list.Index() | ||
|
||
if len(idx.index) != 2 { | ||
t.Errorf("Map has the wrong number of entries.") | ||
} | ||
|
||
_, ok := idx.Get("example") | ||
if ok { | ||
t.Errorf("Entry should not be present.") | ||
} | ||
|
||
entry, ok := idx.Get("GARRON.net") | ||
if !ok { | ||
t.Errorf("Entry should be present.") | ||
} | ||
if entry.Mode != "ForceHTTPS" { | ||
t.Errorf("Map has invalid entry.") | ||
} | ||
} | ||
|
||
func TestNewFromLatest(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping test to avoid preload list download.") | ||
} | ||
|
||
list, err := NewFromLatest() | ||
if err != nil { | ||
t.Errorf("Could not retrieve preload list.") | ||
} | ||
|
||
firstEntry := list.Entries[0] | ||
if firstEntry.Name != "pinningtest.appspot.com" { | ||
t.Errorf("First entry of preload list does not have the expected name.") | ||
} | ||
} | ||
|
||
func TestNewFromChromiumURL(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping test to avoid preload list download.") | ||
} | ||
|
||
list, err := NewFromChromiumURL("https://chromium.googlesource.com/chromium/src/+/4f587d7d4532287308715d824d19e7465c9f663e/net/http/transport_security_state_static.json?format=TEXT") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if len(list.Entries) != 3558 { | ||
t.Errorf("Wrong number of entries: %d", len(list.Entries)) | ||
} | ||
} | ||
|
||
var ( | ||
testJSON = `{ | ||
"entries": [ | ||
// This is a comment. | ||
{"name": "garron.net", "include_subdomains": true, "mode": "force-https"}, | ||
{"name": "example.com", "include_subdomains": false, "mode": "force-https"}, | ||
{"name": "gmail.com", "mode": "force-https"}, | ||
// Line above intentionally left blank. | ||
{"name": "google.com"}, | ||
{"name": "pinned.badssl.com", "pins": "pinnymcpinnedkey"} | ||
] | ||
}` | ||
testParsed = PreloadList{Entries: []Entry{ | ||
{"garron.net", "force-https", true}, | ||
{"example.com", "force-https", false}, | ||
{"gmail.com", "force-https", false}, | ||
{"google.com", "", false}, | ||
{"pinned.badssl.com", "", false}}, | ||
} | ||
) | ||
|
||
func TestNewFromFile(t *testing.T) { | ||
f, err := ioutil.TempFile("", "preloadlist-test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(f.Name()) | ||
|
||
if _, err := f.Write([]byte(testJSON)); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
list, err := NewFromFile(f.Name()) | ||
if err != nil { | ||
t.Fatalf("Could not read preload list. %s", err) | ||
} | ||
|
||
if !reflect.DeepEqual(list, testParsed) { | ||
t.Errorf("Parsed list does not match expected. %#v", list) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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,9 @@ | ||
{ | ||
"entries": [ | ||
{"name": "garron.net", "include_subdomains": true, "mode": "force-https"}, | ||
{"name": "example.com", "include_subdomains": false, "mode": "force-https"}, | ||
{"name": "gmail.com", "mode": "force-https"} | ||
{"name": "google.com"} | ||
{"name": "pinned.badssl.com", "pins": "pinnymcpinnedkey"} | ||
] | ||
} |