auth
126:34de07217709 Browse Files
Test around client types and secrets. Implement a test that the CreateClient handler will correctly create a confidential client and issue a secret for it. Also, just generally test that clients that are confidential are issued secrets and clients that are public are not.
1.1 --- a/client_test.go Sun Jan 18 05:08:18 2015 -0500 1.2 +++ b/client_test.go Mon Jan 19 04:24:22 2015 -0500 1.3 @@ -980,6 +980,7 @@ 1.4 {`{"type":"public","name":"My Client", "endpoints": ["https://test.secondbit.org/", "https://paddy.io"]}`, http.StatusCreated, response{Clients: []Client{{Name: "My Client", OwnerID: profile.ID, Type: "public"}}, Endpoints: []Endpoint{{URI: "https://test.secondbit.org/"}, {URI: "https://paddy.io"}}}}, 1.5 {`{"type":"public","name":"My Client", "endpoints": [":/not a url", "https://paddy.io"]}`, http.StatusCreated, response{Clients: []Client{{Name: "My Client", OwnerID: profile.ID, Type: "public"}}, Endpoints: []Endpoint{{URI: "https://paddy.io"}}, Errors: []requestError{{Slug: requestErrInvalidFormat, Field: "/endpoints/0"}}}}, 1.6 {`{"type":"public","name":"My Client", "endpoints": [":/not a url", "/relative/uri", "https://paddy.io"]}`, http.StatusCreated, response{Clients: []Client{{Name: "My Client", OwnerID: profile.ID, Type: "public"}}, Endpoints: []Endpoint{{URI: "https://paddy.io"}}, Errors: []requestError{{Slug: requestErrInvalidFormat, Field: "/endpoints/0"}, {Slug: requestErrInvalidValue, Field: "/endpoints/1"}}}}, 1.7 + {`{"type":"confidential","name":"Secret Client", "endpoints": ["https://secondbit.org"]}`, http.StatusCreated, response{Clients: []Client{{Name: "Secret Client", OwnerID: profile.ID, Type: "confidential"}}, Endpoints: []Endpoint{{URI: "https://secondbit.org"}}}}, 1.8 } 1.9 for pos, test := range tests { 1.10 t.Logf("Test #%d: `%s`", pos, test.request) 1.11 @@ -996,6 +997,15 @@ 1.12 if err != nil { 1.13 t.Error("Unexpected error unmarshalling response:", err) 1.14 } 1.15 + if len(res.Clients) > 0 { 1.16 + if res.Clients[0].Type == "confidential" && res.Clients[0].Secret == "" { 1.17 + t.Log("Client:", res.Clients[0]) 1.18 + t.Error("Expected confidential client to have a secret, but does not.") 1.19 + } else if res.Clients[0].Type == "public" && res.Clients[0].Secret != "" { 1.20 + t.Log("Client:", res.Clients[0]) 1.21 + t.Error("Expected public client to not have a secret, but it does.") 1.22 + } 1.23 + } 1.24 fillInServerGenerated(test.resp, res) 1.25 success, field, expectation, result := compareResponses(test.resp, res) 1.26 if !success {