Skip to content

Commit bf9ce64

Browse files
jshacpu
authored andcommitted
Update GSB library (letsencrypt#3192)
This pulls in google/safebrowsing#74, which introduces a new LookupURLsContext that allows us to pass through timeout information nicely. Also, update calling code to use LookupURLsContext instead of LookupURLs.
1 parent c06dcfa commit bf9ce64

File tree

10 files changed

+98
-42
lines changed

10 files changed

+98
-42
lines changed

Godeps/Godeps.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/boulder-va/gsb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ type gsbAdapter struct {
7171
// IsListed provides the va.SafeBrowsing interface by using the
7272
// `safebrowsing4v.SafeBrowser` to look up one URL and return the first threat
7373
// list it is found on, or "" if the URL is safe.
74-
func (sb gsbAdapter) IsListed(url string) (string, error) {
75-
threats, err := sb.LookupURLs([]string{url})
74+
func (sb gsbAdapter) IsListed(ctx context.Context, url string) (string, error) {
75+
threats, err := sb.LookupURLsContext(ctx, []string{url})
7676
if err != nil {
7777
return "error", err
7878
}

cmd/boulder-va/gsb_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"testing"
67

@@ -65,8 +66,9 @@ func TestV4IsListed(t *testing.T) {
6566
url := "foobar.com"
6667

6768
// We EXPECT that calling `IsListed` on the gsbAdapter will result in a call to the SafeBrowser's `LookupURLs` function
68-
mockSB.EXPECT().LookupURLs([]string{url})
69-
result, err := gsb.IsListed(url)
69+
background := context.Background()
70+
mockSB.EXPECT().LookupURLsContext(background, []string{url})
71+
result, err := gsb.IsListed(background, url)
7072
test.AssertNotError(t, err, fmt.Sprintf("IsListed(%q) returned non-nil err", url))
7173
test.AssertEquals(t, result, "")
7274
}

cmd/boulder-va/mock_gsb/mock_gsb.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Automatically generated by MockGen. DO NOT EDIT!
2-
// Source: va/gsb.go
2+
// Source: ./va/gsb.go
33

44
package mock_gsb
55

66
import (
77
gomock "github.com/golang/mock/gomock"
88
safebrowsing "github.com/google/safebrowsing"
9+
context "golang.org/x/net/context"
910
)
1011

1112
// Mock of SafeBrowsing interface
@@ -29,15 +30,15 @@ func (_m *MockSafeBrowsing) EXPECT() *_MockSafeBrowsingRecorder {
2930
return _m.recorder
3031
}
3132

32-
func (_m *MockSafeBrowsing) IsListed(url string) (string, error) {
33-
ret := _m.ctrl.Call(_m, "IsListed", url)
33+
func (_m *MockSafeBrowsing) IsListed(ctx context.Context, url string) (string, error) {
34+
ret := _m.ctrl.Call(_m, "IsListed", ctx, url)
3435
ret0, _ := ret[0].(string)
3536
ret1, _ := ret[1].(error)
3637
return ret0, ret1
3738
}
3839

39-
func (_mr *_MockSafeBrowsingRecorder) IsListed(arg0 interface{}) *gomock.Call {
40-
return _mr.mock.ctrl.RecordCall(_mr.mock, "IsListed", arg0)
40+
func (_mr *_MockSafeBrowsingRecorder) IsListed(arg0, arg1 interface{}) *gomock.Call {
41+
return _mr.mock.ctrl.RecordCall(_mr.mock, "IsListed", arg0, arg1)
4142
}
4243

4344
// Mock of SafeBrowsingV4 interface
@@ -61,13 +62,13 @@ func (_m *MockSafeBrowsingV4) EXPECT() *_MockSafeBrowsingV4Recorder {
6162
return _m.recorder
6263
}
6364

64-
func (_m *MockSafeBrowsingV4) LookupURLs(urls []string) ([][]safebrowsing.URLThreat, error) {
65-
ret := _m.ctrl.Call(_m, "LookupURLs", urls)
65+
func (_m *MockSafeBrowsingV4) LookupURLsContext(ctx context.Context, urls []string) ([][]safebrowsing.URLThreat, error) {
66+
ret := _m.ctrl.Call(_m, "LookupURLsContext", ctx, urls)
6667
ret0, _ := ret[0].([][]safebrowsing.URLThreat)
6768
ret1, _ := ret[1].(error)
6869
return ret0, ret1
6970
}
7071

71-
func (_mr *_MockSafeBrowsingV4Recorder) LookupURLs(arg0 interface{}) *gomock.Call {
72-
return _mr.mock.ctrl.RecordCall(_mr.mock, "LookupURLs", arg0)
72+
func (_mr *_MockSafeBrowsingV4Recorder) LookupURLsContext(arg0, arg1 interface{}) *gomock.Call {
73+
return _mr.mock.ctrl.RecordCall(_mr.mock, "LookupURLsContext", arg0, arg1)
7374
}

va/gsb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
type SafeBrowsing interface {
1515
// IsListed returns a non-empty string if the domain was bad. Specifically,
1616
// it is which Google Safe Browsing list the domain was found on.
17-
IsListed(url string) (list string, err error)
17+
IsListed(ctx context.Context, url string) (list string, err error)
1818
}
1919

2020
// SafeBrowsingV4 is an interface around the functions from Google
2121
// safebrowsing's v4 API's *SafeBrowser type that we use. Using this interface
2222
// allows mocking for tests
2323
type SafeBrowsingV4 interface {
24-
LookupURLs(urls []string) (threats [][]safebrowsingv4.URLThreat, err error)
24+
LookupURLsContext(ctx context.Context, urls []string) (threats [][]safebrowsingv4.URLThreat, err error)
2525
}
2626

2727
// IsSafeDomain returns true if the domain given is determined to be safe by a
@@ -41,7 +41,7 @@ func (va *ValidationAuthorityImpl) IsSafeDomain(ctx context.Context, req *vaPB.I
4141
}
4242

4343
var status bool
44-
list, err := va.safeBrowsing.IsListed(*req.Domain)
44+
list, err := va.safeBrowsing.IsListed(ctx, *req.Domain)
4545
if err != nil {
4646
stats.Inc("IsSafeDomain.Errors", 1)
4747
// In the event of an error checking the GSB status we allow the domain in

va/gsb_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func TestIsSafeDomain(t *testing.T) {
2525
defer ctrl.Finish()
2626

2727
sbc := NewMockSafeBrowsing(ctrl)
28-
sbc.EXPECT().IsListed("good.com").Return("", nil)
29-
sbc.EXPECT().IsListed("bad.com").Return("bad", nil)
30-
sbc.EXPECT().IsListed("errorful.com").Return("", errors.New("welp"))
28+
sbc.EXPECT().IsListed(gomock.Any(), "good.com").Return("", nil)
29+
sbc.EXPECT().IsListed(gomock.Any(), "bad.com").Return("bad", nil)
30+
sbc.EXPECT().IsListed(gomock.Any(), "errorful.com").Return("", errors.New("welp"))
3131
va := NewValidationAuthorityImpl(
3232
&cmd.PortConfig{},
3333
sbc,

va/mock_gsb_test.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Automatically generated by MockGen. DO NOT EDIT!
2-
// Source: ./gsb.go
2+
// Source: ./va/gsb.go
33

44
package va
55

66
import (
77
gomock "github.com/golang/mock/gomock"
8+
safebrowsing "github.com/google/safebrowsing"
9+
context "golang.org/x/net/context"
810
)
911

1012
// Mock of SafeBrowsing interface
@@ -28,13 +30,45 @@ func (_m *MockSafeBrowsing) EXPECT() *_MockSafeBrowsingRecorder {
2830
return _m.recorder
2931
}
3032

31-
func (_m *MockSafeBrowsing) IsListed(url string) (string, error) {
32-
ret := _m.ctrl.Call(_m, "IsListed", url)
33+
func (_m *MockSafeBrowsing) IsListed(ctx context.Context, url string) (string, error) {
34+
ret := _m.ctrl.Call(_m, "IsListed", ctx, url)
3335
ret0, _ := ret[0].(string)
3436
ret1, _ := ret[1].(error)
3537
return ret0, ret1
3638
}
3739

38-
func (_mr *_MockSafeBrowsingRecorder) IsListed(arg0 interface{}) *gomock.Call {
39-
return _mr.mock.ctrl.RecordCall(_mr.mock, "IsListed", arg0)
40+
func (_mr *_MockSafeBrowsingRecorder) IsListed(arg0, arg1 interface{}) *gomock.Call {
41+
return _mr.mock.ctrl.RecordCall(_mr.mock, "IsListed", arg0, arg1)
42+
}
43+
44+
// Mock of SafeBrowsingV4 interface
45+
type MockSafeBrowsingV4 struct {
46+
ctrl *gomock.Controller
47+
recorder *_MockSafeBrowsingV4Recorder
48+
}
49+
50+
// Recorder for MockSafeBrowsingV4 (not exported)
51+
type _MockSafeBrowsingV4Recorder struct {
52+
mock *MockSafeBrowsingV4
53+
}
54+
55+
func NewMockSafeBrowsingV4(ctrl *gomock.Controller) *MockSafeBrowsingV4 {
56+
mock := &MockSafeBrowsingV4{ctrl: ctrl}
57+
mock.recorder = &_MockSafeBrowsingV4Recorder{mock}
58+
return mock
59+
}
60+
61+
func (_m *MockSafeBrowsingV4) EXPECT() *_MockSafeBrowsingV4Recorder {
62+
return _m.recorder
63+
}
64+
65+
func (_m *MockSafeBrowsingV4) LookupURLsContext(ctx context.Context, urls []string) ([][]safebrowsing.URLThreat, error) {
66+
ret := _m.ctrl.Call(_m, "LookupURLsContext", ctx, urls)
67+
ret0, _ := ret[0].([][]safebrowsing.URLThreat)
68+
ret1, _ := ret[1].(error)
69+
return ret0, ret1
70+
}
71+
72+
func (_mr *_MockSafeBrowsingV4Recorder) LookupURLsContext(arg0, arg1 interface{}) *gomock.Call {
73+
return _mr.mock.ctrl.RecordCall(_mr.mock, "LookupURLsContext", arg0, arg1)
4074
}

vendor/github.com/google/safebrowsing/api.go

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/google/safebrowsing/database.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/google/safebrowsing/safebrowser.go

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)