Skip to content

Commit

Permalink
check validity of invite before accepting
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-bate authored Dec 12, 2017
1 parent 6cafd48 commit 378e504
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 186 deletions.
6 changes: 3 additions & 3 deletions api/forgot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestForgotResponds(t *testing.T) {
method: "PUT",
url: "/accept/forgot",
respCode: 200,
body: jo{
body: testJSONObject{
"key": "1234_aK3yxxx123",
"email": "me@myemail.com",
"password": "myN3wpa55w0rd",
Expand All @@ -48,7 +48,7 @@ func TestForgotResponds(t *testing.T) {
method: "PUT",
url: "/accept/forgot",
respCode: 404,
body: jo{
body: testJSONObject{
"key": "1234_no_match",
"email": "me@myemail.com",
"password": "myN3wpa55w0rd",
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestForgotResponds(t *testing.T) {

if response.Body.Len() != 0 && len(test.response) != 0 {
// compare bodies by comparing the unmarshalled JSON results
var result = &jo{}
var result = &testJSONObject{}

if err := json.NewDecoder(response.Body).Decode(result); err != nil {
t.Logf("Err decoding nonempty response body: [%v]\n [%v]\n", err, response.Body)
Expand Down
6 changes: 3 additions & 3 deletions api/hydrophoneApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type (
}
Config struct {
ServerSecret string `json:"serverSecret"` //used for services
WebURL string `json:"webUrl"`
WebURL string `json:"webUrl"`
AssetURL string `json:"assetUrl"`
}

Expand Down Expand Up @@ -256,15 +256,15 @@ func (a *Api) token(res http.ResponseWriter, req *http.Request) *shoreline.Token
td := a.sl.CheckToken(token)

if td == nil {
statusErr := &status.StatusError{status.NewStatus(http.StatusForbidden, STATUS_INVALID_TOKEN)}
statusErr := &status.StatusError{Status: status.NewStatus(http.StatusForbidden, STATUS_INVALID_TOKEN)}
log.Printf("token %s err[%v] ", STATUS_INVALID_TOKEN, statusErr)
a.sendModelAsResWithStatus(res, statusErr, http.StatusForbidden)
return nil
}
//all good!
return td
}
statusErr := &status.StatusError{status.NewStatus(http.StatusUnauthorized, STATUS_NO_TOKEN)}
statusErr := &status.StatusError{Status: status.NewStatus(http.StatusUnauthorized, STATUS_NO_TOKEN)}
log.Printf("token %s err[%v] ", STATUS_NO_TOKEN, statusErr)
a.sendModelAsResWithStatus(res, statusErr, http.StatusUnauthorized)
return nil
Expand Down
15 changes: 8 additions & 7 deletions api/hydrophoneApi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,21 @@ func (m *testingShorelingMock) CheckToken(token string) *shoreline.TokenData {
type (
//common test structure
toTest struct {
desc string
skip bool
returnNone bool
method string
url string
body jo
body testJSONObject
token string
respCode int
response jo
response testJSONObject
}
// These two types make it easier to define blobs of json inline.
// We don't use the types defined by the API because we want to
// be able to test with partial data structures.
// jo is a generic json object
jo map[string]interface{}
// testJSONObject is a generic json object
testJSONObject map[string]interface{}

// and ja is a generic json array
ja []interface{}
Expand Down Expand Up @@ -153,10 +154,10 @@ func TestGetStatus_StatusInternalServerError(t *testing.T) {
}
}

func (i *jo) deepCompare(j *jo) string {
for k, _ := range *i {
func (i *testJSONObject) deepCompare(j *testJSONObject) string {
for k := range *i {
if reflect.DeepEqual((*i)[k], (*j)[k]) == false {
return fmt.Sprintf("for [%s] was [%v] expected [%v] ", k, (*i)[k], (*j)[k])
return fmt.Sprintf("`%s` expected `%v` actual `%v` ", k, (*j)[k], (*i)[k])
}
}
return ""
Expand Down
Loading

2 comments on commit 378e504

@jh-bate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jh-bate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.