"Full" in Auth endpoint name is no longer useful
This commit is contained in:
parent
8b3f395f0e
commit
eccef61d0b
7 changed files with 23 additions and 25 deletions
|
@ -10,20 +10,20 @@ import (
|
||||||
|
|
||||||
// DeviceId is decided by the device. UserId is decided by the server, and is
|
// DeviceId is decided by the device. UserId is decided by the server, and is
|
||||||
// gatekept by Email/Password
|
// gatekept by Email/Password
|
||||||
type AuthFullRequest struct {
|
type AuthRequest struct {
|
||||||
DeviceId auth.DeviceId `json:"deviceId"`
|
DeviceId auth.DeviceId `json:"deviceId"`
|
||||||
Email auth.Email `json:"email"`
|
Email auth.Email `json:"email"`
|
||||||
Password auth.Password `json:"password"`
|
Password auth.Password `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AuthFullRequest) validate() bool {
|
func (r *AuthRequest) validate() bool {
|
||||||
return (r.DeviceId != "" &&
|
return (r.DeviceId != "" &&
|
||||||
r.Email != auth.Email("") && // TODO email validation. Here or store. Stdlib does it: https://stackoverflow.com/a/66624104
|
r.Email != auth.Email("") && // TODO email validation. Here or store. Stdlib does it: https://stackoverflow.com/a/66624104
|
||||||
r.Password != auth.Password(""))
|
r.Password != auth.Password(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getAuthTokenFull(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) getAuthToken(w http.ResponseWriter, req *http.Request) {
|
||||||
var authRequest AuthFullRequest
|
var authRequest AuthRequest
|
||||||
if !getPostData(w, req, &authRequest) {
|
if !getPostData(w, req, &authRequest) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ func TestServerAuthHandlerSuccess(t *testing.T) {
|
||||||
|
|
||||||
requestBody := []byte(`{"deviceId": "dev-1", "email": "abc@example.com", "password": "123"}`)
|
requestBody := []byte(`{"deviceId": "dev-1", "email": "abc@example.com", "password": "123"}`)
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, PathAuthTokenFull, bytes.NewBuffer(requestBody))
|
req := httptest.NewRequest(http.MethodPost, PathAuthToken, bytes.NewBuffer(requestBody))
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
s.getAuthTokenFull(w, req)
|
s.getAuthToken(w, req)
|
||||||
body, _ := ioutil.ReadAll(w.Body)
|
body, _ := ioutil.ReadAll(w.Body)
|
||||||
|
|
||||||
var result auth.AuthToken
|
var result auth.AuthToken
|
||||||
|
@ -130,10 +130,10 @@ func TestServerAuthHandlerErrors(t *testing.T) {
|
||||||
server := Server{&testAuth, &testStore, &wallet.WalletUtil{}}
|
server := Server{&testAuth, &testStore, &wallet.WalletUtil{}}
|
||||||
|
|
||||||
// Make request
|
// Make request
|
||||||
req := httptest.NewRequest(tc.method, PathAuthTokenFull, bytes.NewBuffer([]byte(tc.requestBody)))
|
req := httptest.NewRequest(tc.method, PathAuthToken, bytes.NewBuffer([]byte(tc.requestBody)))
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
server.getAuthTokenFull(w, req)
|
server.getAuthToken(w, req)
|
||||||
|
|
||||||
if want, got := tc.expectedStatusCode, w.Result().StatusCode; want != got {
|
if want, got := tc.expectedStatusCode, w.Result().StatusCode; want != got {
|
||||||
t.Errorf("StatusCode: expected %d, got %d", want, got)
|
t.Errorf("StatusCode: expected %d, got %d", want, got)
|
||||||
|
@ -153,7 +153,7 @@ func TestServerAuthHandlerErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerValidateAuthFullRequest(t *testing.T) {
|
func TestServerValidateAuthRequest(t *testing.T) {
|
||||||
t.Fatalf("Test me: Implement and test AuthFullRequest.validate()")
|
t.Fatalf("Test me: Implement and test AuthRequest.validate()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,8 @@ func TestIntegrationWalletUpdates(t *testing.T) {
|
||||||
responseBody, statusCode = request(
|
responseBody, statusCode = request(
|
||||||
t,
|
t,
|
||||||
http.MethodPost,
|
http.MethodPost,
|
||||||
s.getAuthTokenFull,
|
s.getAuthToken,
|
||||||
PathAuthTokenFull,
|
PathAuthToken,
|
||||||
&authToken1,
|
&authToken1,
|
||||||
`{"deviceId": "dev-1", "email": "abc@example.com", "password": "123"}`,
|
`{"deviceId": "dev-1", "email": "abc@example.com", "password": "123"}`,
|
||||||
)
|
)
|
||||||
|
@ -117,8 +117,8 @@ func TestIntegrationWalletUpdates(t *testing.T) {
|
||||||
responseBody, statusCode = request(
|
responseBody, statusCode = request(
|
||||||
t,
|
t,
|
||||||
http.MethodPost,
|
http.MethodPost,
|
||||||
s.getAuthTokenFull,
|
s.getAuthToken,
|
||||||
PathAuthTokenFull,
|
PathAuthToken,
|
||||||
&authToken2,
|
&authToken2,
|
||||||
`{"deviceId": "dev-2", "email": "abc@example.com", "password": "123"}`,
|
`{"deviceId": "dev-2", "email": "abc@example.com", "password": "123"}`,
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
// TODO proper doc comments!
|
// TODO proper doc comments!
|
||||||
|
|
||||||
const PathAuthTokenFull = "/auth/full"
|
const PathAuthToken = "/auth/full"
|
||||||
const PathRegister = "/signup"
|
const PathRegister = "/signup"
|
||||||
const PathWalletState = "/wallet-state"
|
const PathWalletState = "/wallet-state"
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ func (s *Server) checkAuth(
|
||||||
// PUT = "...creates a new resource or replaces a representation of the target resource with the request payload."
|
// PUT = "...creates a new resource or replaces a representation of the target resource with the request payload."
|
||||||
|
|
||||||
func (s *Server) Serve() {
|
func (s *Server) Serve() {
|
||||||
http.HandleFunc(PathAuthTokenFull, s.getAuthTokenFull)
|
http.HandleFunc(PathAuthToken, s.getAuthToken)
|
||||||
http.HandleFunc(PathWalletState, s.handleWalletState)
|
http.HandleFunc(PathWalletState, s.handleWalletState)
|
||||||
http.HandleFunc(PathRegister, s.register)
|
http.HandleFunc(PathRegister, s.register)
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ Registered
|
||||||
Now that the account exists, grab an auth token with both clients.
|
Now that the account exists, grab an auth token with both clients.
|
||||||
|
|
||||||
```
|
```
|
||||||
>>> c1.get_full_auth_token()
|
>>> c1.get_auth_token()
|
||||||
Got auth token: 941e5159a2caff15f0bdc1c0e6da92691d3073543dbfae810cfe57d51c35f0e0
|
Got auth token: 941e5159a2caff15f0bdc1c0e6da92691d3073543dbfae810cfe57d51c35f0e0
|
||||||
>>> c2.get_full_auth_token()
|
>>> c2.get_auth_token()
|
||||||
Got auth token: b323a18e51263ac052777ca68de716c1f3b4983bf4c918477e355f637c8ea2d4
|
Got auth token: b323a18e51263ac052777ca68de716c1f3b4983bf4c918477e355f637c8ea2d4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ Now that the account exists, grab an auth token with both clients.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
code_block("""
|
code_block("""
|
||||||
c1.get_full_auth_token()
|
c1.get_auth_token()
|
||||||
c2.get_full_auth_token()
|
c2.get_auth_token()
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# TODO - wait isn't it redundant to have the `deviceId` field, for the same reason it's redundant to have the `sequence` field?
|
# TODO - wait isn't it redundant to have the `deviceId` field, for the same reason it's redundant to have the `sequence` field?
|
||||||
|
|
|
@ -3,7 +3,7 @@ import random, string, json, uuid, requests, hashlib
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
BASE_URL = 'http://localhost:8090'
|
BASE_URL = 'http://localhost:8090'
|
||||||
AUTH_FULL_URL = BASE_URL + '/auth/full'
|
AUTH_URL = BASE_URL + '/auth/full'
|
||||||
REGISTER_URL = BASE_URL + '/signup'
|
REGISTER_URL = BASE_URL + '/signup'
|
||||||
WALLET_STATE_URL = BASE_URL + '/wallet-state'
|
WALLET_STATE_URL = BASE_URL + '/wallet-state'
|
||||||
|
|
||||||
|
@ -97,15 +97,13 @@ class Client():
|
||||||
return
|
return
|
||||||
print ("Registered")
|
print ("Registered")
|
||||||
|
|
||||||
# TODO - Rename to get_auth_token. same in go. Remember to grep, gotta change
|
def get_auth_token(self):
|
||||||
# it in README as well.
|
|
||||||
def get_full_auth_token(self):
|
|
||||||
body = json.dumps({
|
body = json.dumps({
|
||||||
'email': self.email,
|
'email': self.email,
|
||||||
'password': create_login_password(self.root_password),
|
'password': create_login_password(self.root_password),
|
||||||
'deviceId': self.device_id,
|
'deviceId': self.device_id,
|
||||||
})
|
})
|
||||||
response = requests.post(AUTH_FULL_URL, body)
|
response = requests.post(AUTH_URL, body)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print ('Error', response.status_code)
|
print ('Error', response.status_code)
|
||||||
print (response.content)
|
print (response.content)
|
||||||
|
|
Loading…
Reference in a new issue