Skip to content

Commit

Permalink
Merge pull request #14 from mhilton/188-update-dependencies
Browse files Browse the repository at this point in the history
all: update dependencies
  • Loading branch information
mhilton committed Apr 15, 2020
2 parents 7f8433c + f3a29da commit 34a1f99
Show file tree
Hide file tree
Showing 67 changed files with 756 additions and 693 deletions.
12 changes: 6 additions & 6 deletions candidclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func testIdentityClient(c *qt.C, candidClient identchecker.IdentityClient, bclie
derr := errgo.Cause(authErr).(*bakery.DischargeRequiredError)

m, err := b.Oven.NewMacaroon(context.TODO(), bakery.LatestVersion, derr.Caveats, derr.Ops...)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

ms, err := bclient.DischargeAll(context.TODO(), m)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

// Make sure that the macaroon discharged correctly and that it
// has the right declared caveats.
authInfo, err := b.Checker.Auth(ms).Allow(context.TODO(), identchecker.LoginOp)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

c.Assert(authInfo.Identity, qt.Not(qt.IsNil))
c.Assert(authInfo.Identity.Id(), qt.Equals, expectId)
Expand All @@ -83,14 +83,14 @@ func testIdentityClient(c *qt.C, candidClient identchecker.IdentityClient, bclie
user := authInfo.Identity.(candidclient.Identity)

u, err := user.Username()
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(u, qt.Equals, expectUser)
ok, err := user.Allow(context.TODO(), []string{expectGroups[0]})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)

groups, err := user.Groups()
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
sort.Strings(groups)
c.Assert(groups, qt.DeepEquals, expectGroups)
}
30 changes: 15 additions & 15 deletions candidclient/permcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,58 @@ func TestPermChecker(t *testing.T) {
BaseURL: srv.URL.String(),
Client: srv.Client("server-user"),
})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

pc := candidclient.NewPermChecker(client, time.Hour)

// No permissions always yields false.
ok, err := pc.Allow("bob", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, false)

// If the user isn't found, we return a (false, nil)
ok, err = pc.Allow("bob", []string{"beatles"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, false)

// If the perms allow everyone, it's ok
ok, err = pc.Allow("bob", []string{"noone", "everyone"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)

// If the perms allow everyone@somewhere, it's ok.
ok, err = pc.Allow("bob@somewhere", []string{"everyone@somewhere"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)

// Check that the everyone@x logic works with multiple @s.
ok, err = pc.Allow("bob@foo@somewhere@else", []string{"everyone@somewhere@else"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)

// Check that we're careful enough about "everyone" as a prefix
// to a user name.
ok, err = pc.Allow("bobx", []string{"everyonex"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, false)

// If the perms allow the user itself, it's ok
ok, err = pc.Allow("bob", []string{"noone", "bob"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)

srv.AddUser("bob", "beatles")

// The group details are currently cached by the client,
// so the original request will still fail.
ok, err = pc.Allow("bob", []string{"beatles"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, false)

// Clearing the cache allows it to succeed.
pc.CacheEvictAll()
ok, err = pc.Allow("bob", []string{"beatles"})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(ok, qt.Equals, true)
}

Expand All @@ -90,30 +90,30 @@ func TestGroupCache(t *testing.T) {
BaseURL: srv.URL.String(),
Client: srv.Client("server-user"),
})
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

cache := candidclient.NewGroupCache(client, time.Hour)

// If the user isn't found, we retturn no groups.
g, err := cache.Groups("bob")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(g, qt.HasLen, 0)

g, err = cache.Groups("alice")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(g, qt.DeepEquals, []string{"othergroup", "somegroup"})

srv.AddUser("bob", "beatles")

// The group details are currently cached by the client,
// so we'll still see the original group membership.
g, err = cache.Groups("bob")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(g, qt.HasLen, 0)

// Clearing the cache allows it to succeed.
cache.CacheEvictAll()
g, err = cache.Groups("bob")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(g, qt.DeepEquals, []string{"beatles"})
}
6 changes: 3 additions & 3 deletions candidclient/redirect/redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestInteractor(t *testing.T) {
c.Assert(i.Kind(), qt.Equals, redirect.Kind)

req, err := http.NewRequest("GET", "https://www.example.com/discharge", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
irerr := httpbakery.NewInteractionRequiredError(nil, req)
// Fake an empty InteractionRequiredError
irerr.Info = &httpbakery.ErrorInfo{}
Expand All @@ -65,7 +65,7 @@ func TestInteractor(t *testing.T) {
}
i.SetDischargeToken("https://www.example.com/login", dt)
dt2, err := i.Interact(ctx, nil, "", irerr)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(*dt2, qt.DeepEquals, *dt)
}

Expand All @@ -74,7 +74,7 @@ func TestParseLoginResult(t *testing.T) {

state, code, err := redirect.ParseLoginResult("https://example.com/callback?state=12345&code=54321")
c.Assert(state, qt.Equals, "12345")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(code, qt.Equals, "54321")

state, code, err = redirect.ParseLoginResult("https://example.com/callback?state=12345&error_code=ec&error=test+error")
Expand Down
22 changes: 11 additions & 11 deletions candidclient/ussodischarge/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func (s *clientSuite) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (s *clientSuite) Init(c *qt.C) {
var err error
s.testMacaroon, err = bakery.NewMacaroon([]byte("test rootkey"), []byte("test macaroon"), "test location", bakery.LatestVersion, nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
// Discharge macaroons from Ubuntu SSO will be binary encoded in the version 1 format.
s.testDischargeMacaroon, err = macaroon.New([]byte("test discharge rootkey"), []byte("test discharge macaroon"), "test discharge location", macaroon.V1)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

s.srv = httptest.NewServer(s)
c.Defer(s.srv.Close)
Expand All @@ -78,7 +78,7 @@ func (s *clientSuite) Init(c *qt.C) {
func (s *clientSuite) TestMacaroon(c *qt.C) {
s.macaroon = s.testMacaroon
m, err := ussodischarge.Macaroon(testContext, nil, s.srv.URL+"/macaroon")
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(m.M(), macaroonEquals, s.testMacaroon.M())
}

Expand All @@ -96,11 +96,11 @@ func (s *clientSuite) TestVisitor(c *qt.C) {

client := httpbakery.NewClient()
req, err := http.NewRequest("GET", "", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
ierr := httpbakery.NewInteractionRequiredError(nil, req)
ussodischarge.SetInteraction(ierr, s.srv.URL+"/login")
dt, err := v.Interact(testContext, client, "", ierr)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(dt, qt.DeepEquals, &httpbakery.DischargeToken{
Kind: "test-kind",
Value: []byte("test-value"),
Expand All @@ -113,7 +113,7 @@ func (s *clientSuite) TestVisitorMethodNotSupported(c *qt.C) {
})
client := httpbakery.NewClient()
req, err := http.NewRequest("GET", "", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
ierr := httpbakery.NewInteractionRequiredError(nil, req)
ierr.SetInteraction("other", nil)
dt, err := v.Interact(testContext, client, "", ierr)
Expand All @@ -127,7 +127,7 @@ func (s *clientSuite) TestVisitorFunctionError(c *qt.C) {
})
client := httpbakery.NewClient()
req, err := http.NewRequest("GET", "", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
ierr := httpbakery.NewInteractionRequiredError(nil, req)
ussodischarge.SetInteraction(ierr, s.srv.URL+"/login")
dt, err := v.Interact(testContext, client, "", ierr)
Expand All @@ -146,7 +146,7 @@ func (s *clientSuite) TestAcquireDischarge(c *qt.C) {
Location: s.srv.URL,
Id: []byte("test caveat id"),
}, nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(m.M(), macaroonEquals, s.testDischargeMacaroon)
}

Expand All @@ -167,14 +167,14 @@ func (s *clientSuite) TestAcquireDischargeError(c *qt.C) {
func (s *clientSuite) TestDischargeAll(c *qt.C) {
m := s.testMacaroon.Clone()
err := m.M().AddThirdPartyCaveat([]byte("third party root key"), []byte("third party caveat id"), s.srv.URL)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
d := &ussodischarge.Discharger{
Email: "user@example.com",
Password: "secret",
OTP: "123456",
}
ms, err := d.DischargeAll(testContext, m)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
md := s.testDischargeMacaroon.Clone()
md.Bind(m.M().Signature())
c.Assert(ms, macaroonEquals, macaroon.Slice{m.M(), md})
Expand All @@ -183,7 +183,7 @@ func (s *clientSuite) TestDischargeAll(c *qt.C) {
func (s *clientSuite) TestDischargeAllError(c *qt.C) {
m := s.testMacaroon.Clone()
err := m.M().AddThirdPartyCaveat([]byte("third party root key"), []byte("third party caveat id"), s.srv.URL)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
d := &ussodischarge.Discharger{
Email: "user@example.com",
Password: "bad-secret",
Expand Down
2 changes: 1 addition & 1 deletion candidclient/ussodischarge/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestUnmarshalUSSOMacaroon(t *testing.T) {
data := []byte(`"MDAxYmxvY2F0aW9uIHRlc3QgbG9jYXRpb24KMDAxZGlkZW50aWZpZXIgdGVzdCBtYWNhcm9vbgowMDJmc2lnbmF0dXJlICaaplwsJeHwPuBK6er_d3DnEnSJ2b85-V9SXsiL6xWOCg"`)
var m ussodischarge.USSOMacaroon
err := json.Unmarshal(data, &m)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(string(m.Macaroon.Id()), qt.Equals, "test macaroon")
}

Expand Down
16 changes: 8 additions & 8 deletions candidclient/ussologin/ussologin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func TestPutGetToken(t *testing.T) {
path := filepath.Join(c.Mkdir(), "subdir", "tokenFile")
store := ussologin.NewFileTokenStore(path)
err := store.Put(token)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)

tok, err := store.Get()
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(tok, qt.DeepEquals, token)
data, err := ioutil.ReadFile(path)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
var storedToken *usso.SSOData
err = json.Unmarshal(data, &storedToken)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(token, qt.DeepEquals, storedToken)
}

Expand All @@ -54,7 +54,7 @@ func TestReadInvalidToken(t *testing.T) {

path := fmt.Sprintf("%s/tokenFile", c.Mkdir())
err := ioutil.WriteFile(path, []byte("foobar"), 0700)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
store := ussologin.NewFileTokenStore(path)

_, err = store.Get()
Expand All @@ -81,7 +81,7 @@ func TestTokenInStore(t *testing.T) {
}
ctx := context.Background()
tok, err := g.GetToken(ctx)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(tok, qt.DeepEquals, testToken)
c.Assert(st.Calls(), qt.DeepEquals, []jt.StubCall{{
FuncName: "Get",
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestTokenNotInStore(t *testing.T) {
}
ctx := context.Background()
tok, err := g.GetToken(ctx)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(tok, qt.DeepEquals, testToken)
c.Assert(st.Calls(), qt.DeepEquals, []jt.StubCall{{
FuncName: "Get",
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestCorrectUserPasswordSentToUSSOServer(t *testing.T) {
Name: "testToken",
}
_, err := tg.GetToken(context.Background())
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
calls := ussoStub.Calls()
c.Assert(len(calls) > 0, qt.Equals, true)
c.Assert(calls[0], qt.DeepEquals, jt.StubCall{
Expand Down
6 changes: 3 additions & 3 deletions candidclient/ussologin/visitwebpage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestInteractNotSupportedError(t *testing.T) {

i := ussologin.NewInteractor(nil)
req, err := http.NewRequest("GET", "", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
ierr := httpbakery.NewInteractionRequiredError(nil, req)
httpbakery.SetLegacyInteraction(ierr, "", "")
_, err = i.Interact(context.Background(), nil, "", ierr)
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestAuthenticatedRequest(t *testing.T) {
}))
ierr := interactionRequiredError(c, server.URL)
dt, err := i.Interact(context.Background(), httpbakery.NewClient(), "", ierr)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
c.Assert(dt, qt.DeepEquals, &httpbakery.DischargeToken{
Kind: "test",
Value: []byte("test-token"),
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestAuthenticatedRequestError(t *testing.T) {

func interactionRequiredError(c *qt.C, url string) *httpbakery.Error {
req, err := http.NewRequest("GET", "", nil)
c.Assert(err, qt.Equals, nil)
c.Assert(err, qt.IsNil)
ierr := httpbakery.NewInteractionRequiredError(nil, req)
ussologin.SetInteraction(ierr, url)
return ierr
Expand Down
Loading

0 comments on commit 34a1f99

Please sign in to comment.