Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jhbate/oauth-requires'
Browse files Browse the repository at this point in the history
  • Loading branch information
darinkrauss committed Dec 15, 2015
2 parents c3ae229 + 114eea5 commit 37ac6f3
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 355 deletions.
8 changes: 7 additions & 1 deletion clients/gatekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ import (
type (
//Inteface so that we can mock gatekeeperClient for tests
Gatekeeper interface {
//userID -- the Tidepool-assigned userID
//groupID -- the Tidepool-assigned groupID
//
// returns the Permissions
UserInGroup(userID, groupID string) (map[string]Permissions, error)
//userID -- the Tidepool-assigned userID
//groupID -- the Tidepool-assigned groupID
//permissions -- the permisson we want to give the user for the group
SetPermissions(userID, groupID string, permissions Permissions) (map[string]Permissions, error)
getHost() *url.URL
}

gatekeeperClient struct {
Expand Down
37 changes: 0 additions & 37 deletions clients/gatekeeperMock.go

This file was deleted.

62 changes: 0 additions & 62 deletions clients/gatekeeperMock_test.go

This file was deleted.

45 changes: 45 additions & 0 deletions clients/mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package clients

import (
"encoding/json"
)

type (
GatekeeperMock struct{}
SeagullMock struct{}
)

//A mock of the Gatekeeper interface
func NewGatekeeperMock() *GatekeeperMock {
return &GatekeeperMock{}
}

func (mock *GatekeeperMock) UserInGroup(userID, groupID string) (map[string]Permissions, error) {
perms := make(map[string]Permissions)
p := make(Permissions)
p["userid"] = userID
perms["root"] = p

return perms, nil
}

func (mock *GatekeeperMock) SetPermissions(userID, groupID string, permissions Permissions) (map[string]Permissions, error) {
perms := make(map[string]Permissions)
permissions["userid"] = userID
perms["root"] = permissions
return perms, nil
}

//A mock of the Seagull interface
func NewSeagullMock() *SeagullMock {
return &SeagullMock{}
}

func (mock *SeagullMock) GetPrivatePair(userID, hashName, token string) *PrivatePair {
return &PrivatePair{ID: "mock.id.123", Value: "mock value"}
}

func (mock *SeagullMock) GetCollection(userID, collectionName, token string, v interface{}) error {
json.Unmarshal([]byte(`{"Something":"anit no thing"}`), &v)
return nil
}
64 changes: 64 additions & 0 deletions clients/mocks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package clients

import (
"testing"
)

//The purpose of this test is to ensure you canreply on the mocks

const USERID, GROUPID, TOKEN_MOCK = "123user", "456group", "this is a token"

func makeExpectedPermissons() map[string]Permissions {
expected := make(map[string]Permissions)
p := make(Permissions)
p["userid"] = USERID
expected["root"] = p
return expected
}

func TestGatekeeperMock_UserInGroup(t *testing.T) {

expected := makeExpectedPermissons()

gkc := NewGatekeeperMock()

if perms, err := gkc.UserInGroup(USERID, GROUPID); err != nil {
t.Fatal("No error should be returned")
} else if perms == nil || perms["root"]["userid"] != expected["root"]["userid"] {
t.Fatalf("Perms where [%v] but expected [%v]", perms, expected)
}
}
func TestGatekeeperMock_SetPermissions(t *testing.T) {

gkc := NewGatekeeperMock()

expected := makeExpectedPermissons()

if perms, err := gkc.SetPermissions(USERID, GROUPID, expected["root"]); err != nil {
t.Fatal("No error should be returned")
} else if perms == nil || perms["root"]["userid"] != expected["root"]["userid"] {
t.Fatalf("Perms where [%v] but expected [%v]", perms, expected)

}
}

func TestSeagullMock_GetCollection(t *testing.T) {

sc := NewSeagullMock()
var col struct{ Something string }

sc.GetCollection("123.456", "stuff", TOKEN_MOCK, &col)

if col.Something != "anit no thing" {
t.Error("Should have given mocked collection")
}
}

func TestSeagullMock_GetPrivatePair(t *testing.T) {
sc := NewSeagullMock()

if pp := sc.GetPrivatePair("123.456", "Stuff", TOKEN_MOCK); pp == nil {
t.Error("Should give us mocked private pair")
}

}
21 changes: 11 additions & 10 deletions clients/seagull.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import (
)

type (
/*Seagull interface we export*/
Seagull interface {
// Retrieves arbitrary collection information from metadata
//
// userID -- the Tidepool-assigned userId
// hashName -- the name of what we are trying to get
// token -- a server token or the user token
GetPrivatePair(userID, hashName, token string) *PrivatePair
// Retrieves arbitrary collection information from metadata
//
// userID -- the Tidepool-assigned userId
// collectionName -- the collection being retrieved
// token -- a server token or the user token
// v - the interface to return the value in
GetCollection(userID, collectionName, token string, v interface{}) error
getHost() *url.URL
}

seagullClient struct {
Expand Down Expand Up @@ -93,14 +102,6 @@ func (client *seagullClient) GetPrivatePair(userID, hashName, token string) *Pri
return &retVal
}

/*
* Retrieves arbitrary collection information from metadata
*
* userID -- the Tidepool-assigned userId
* collectionName -- the collection being retrieved
* token -- a server token or the user token
* v - the interface to return the value in
*/
func (client *seagullClient) GetCollection(userID, collectionName, token string, v interface{}) error {
host := client.getHost()
if host == nil {
Expand Down
41 changes: 0 additions & 41 deletions clients/seagullMock.go

This file was deleted.

31 changes: 0 additions & 31 deletions clients/seagullMock_test.go

This file was deleted.

Loading

0 comments on commit 37ac6f3

Please sign in to comment.