auth

Paddy 2015-05-17 Parent:8ecb60d29b0d

173:b0d1b3e39fc8 Go to Latest

auth/request_test.go

Make client use our auth(n/z) scheme. Our auth(n/z) scheme can be loosely defined as "encrypted tokens that nginx transforms into headers" and "scopes for bypassing ACL". Our Go client, which is what we'll be using to have services communicate with each other, follows this paradigm now by auto-injecting the headers we'll need to identify ourselves. This will work behind our firewall, but will be useless for the rest of the world, which will need to go through the nginx bastion that can strip the headers and replace them with the headers appropriate to the token attached to the request. This did involve setting a static client ID as the client for our email_verification listener. Ideally, this would cause Client registration (using that ID) when the listener starts up, ignoring ErrClientAlreadyExists. I don't want to have to write the code that will allow us to bypass the Client ACL properly right now, though, so we're just going to have to remember to manually create that Client. Or not. I don't think it will do any harm (outside the OAuth flow) to be using a Client ID that doesn't actually point to a Client. I just think it'd be good for record-keeping purposes.

History
1 package auth
3 import "fmt"
5 func compareErrors(err1, err2 RequestError) (success bool, field string, val1, val2 interface{}) {
6 if err1.Slug != err2.Slug {
7 return false, "Slug", err1.Slug, err2.Slug
8 }
9 if err1.Field != err2.Field {
10 return false, "Field", err1.Field, err2.Field
11 }
12 if err1.Param != err2.Param {
13 return false, "Param", err1.Param, err2.Param
14 }
15 if err1.Header != err2.Header {
16 return false, "Header", err1.Header, err2.Header
17 }
18 return true, "", nil, nil
19 }
21 func compareResponses(resp1, resp2 Response) (success bool, field string, val1, val2 interface{}) {
22 if len(resp1.Errors) != len(resp2.Errors) {
23 return false, "Errors", resp1.Errors, resp2.Errors
24 }
25 if len(resp1.Logins) != len(resp2.Logins) {
26 return false, "Logins", resp1.Logins, resp2.Logins
27 }
28 if len(resp1.Profiles) != len(resp2.Profiles) {
29 return false, "Profiles", resp1.Profiles, resp2.Profiles
30 }
31 if len(resp1.Clients) != len(resp2.Clients) {
32 return false, "Clients", resp1.Clients, resp2.Clients
33 }
34 if len(resp1.Endpoints) != len(resp2.Endpoints) {
35 return false, "Endpoints", resp1.Endpoints, resp2.Endpoints
36 }
37 for pos := range resp1.Errors {
38 success, field, val1, val2 = compareErrors(resp1.Errors[pos], resp2.Errors[pos])
39 if !success {
40 field = fmt.Sprintf("Error %d %s", pos, field)
41 return
42 }
43 }
44 for pos := range resp1.Logins {
45 success, field, val1, val2 = compareLogins(resp1.Logins[pos], resp2.Logins[pos])
46 if !success {
47 field = fmt.Sprintf("Login %d %s", pos, field)
48 return
49 }
50 }
51 for pos := range resp1.Profiles {
52 success, field, val1, val2 = compareProfiles(resp1.Profiles[pos], resp2.Profiles[pos])
53 if !success {
54 field = fmt.Sprintf("Profile %d %s", pos, field)
55 return
56 }
57 }
58 for pos := range resp1.Clients {
59 success, field, val1, val2 = compareClients(resp1.Clients[pos], resp2.Clients[pos])
60 if !success {
61 field = fmt.Sprintf("Client %d %s", pos, field)
62 return
63 }
64 }
65 for pos := range resp1.Endpoints {
66 success, field, val1, val2 = compareEndpoints(resp1.Endpoints[pos], resp2.Endpoints[pos])
67 if !success {
68 field = fmt.Sprintf("Endpoint %d %s", pos, field)
69 return
70 }
71 }
72 return true, "", nil, nil
73 }
75 func fillInServerGenerated(expectation, result Response) {
76 if len(expectation.Profiles) > 0 {
77 for pos, profile := range expectation.Profiles {
78 profile.ID = result.Profiles[pos].ID
79 profile.Created = result.Profiles[pos].Created
80 profile.LastSeen = result.Profiles[pos].LastSeen
81 expectation.Profiles[pos] = profile
82 }
83 }
84 if len(expectation.Logins) > 0 {
85 for pos, login := range expectation.Logins {
86 login.ProfileID = result.Logins[pos].ProfileID
87 login.Created = result.Logins[pos].Created
88 login.LastUsed = result.Logins[pos].LastUsed
89 expectation.Logins[pos] = login
90 }
91 }
92 if len(expectation.Clients) > 0 {
93 for pos, client := range expectation.Clients {
94 client.ID = result.Clients[pos].ID
95 client.Secret = result.Clients[pos].Secret
96 client.OwnerID = result.Clients[pos].OwnerID
97 expectation.Clients[pos] = client
98 }
99 }
100 if len(expectation.Endpoints) > 0 {
101 for pos, endpoint := range expectation.Endpoints {
102 endpoint.ID = result.Endpoints[pos].ID
103 endpoint.ClientID = result.Endpoints[pos].ClientID
104 endpoint.Added = result.Endpoints[pos].Added
105 expectation.Endpoints[pos] = endpoint
106 }
107 }
108 }