auth
auth/oauth2_test.go
Break client verification out, break token returns out. Break client verification out into a helper function to avoid rewriting it for pretty much every grant. Break token returns out into a new function as part of the GrantType, so that implicit grants can redirect with the token value. Split returning the token as JSON into its own exported function, which can be used in multiple grants. Return more relevant information to the template when a user is deciding whether or not to authorize a grant.
1.1 --- a/oauth2_test.go Sat Dec 06 03:33:11 2014 -0500 1.2 +++ b/oauth2_test.go Sun Dec 07 02:52:39 2014 -0500 1.3 @@ -64,9 +64,17 @@ 1.4 if err != nil { 1.5 t.Fatal("Can't store endpoint:", err) 1.6 } 1.7 + profile := Profile{ 1.8 + ID: uuid.NewID(), 1.9 + } 1.10 + err = testContext.SaveProfile(profile) 1.11 + if err != nil { 1.12 + t.Fatal("Can't store profile:", err) 1.13 + } 1.14 session := Session{ 1.15 - ID: "testsession", 1.16 - Active: true, 1.17 + ID: "testsession", 1.18 + Active: true, 1.19 + ProfileID: profile.ID, 1.20 } 1.21 err = testContext.CreateSession(session) 1.22 if err != nil { 1.23 @@ -792,6 +800,7 @@ 1.24 err = json.Unmarshal(w.Body.Bytes(), &resp) 1.25 if err != nil { 1.26 t.Error("Error unmarshalling response:", err) 1.27 + t.Error("Response:", w.Body.String()) 1.28 } 1.29 if resp.AccessToken == "" { 1.30 t.Error("Got blank access token back") 1.31 @@ -810,7 +819,7 @@ 1.32 t.Error("Error retrieving token:", err) 1.33 } 1.34 if len(tokens) != 1 { 1.35 - t.Errorf("Expected %d tokens, got %d", 1, len(tokens)) 1.36 + t.Fatalf("Expected %d tokens, got %d", 1, len(tokens)) 1.37 } 1.38 if tokens[0].AccessToken != resp.AccessToken { 1.39 t.Errorf(`Expected access token to be "%s", got "%s"`, tokens[0].AccessToken, resp.AccessToken)