Delete some things we don't need anymore
This commit is contained in:
parent
0bf11b059c
commit
41721a8f70
7 changed files with 8 additions and 80 deletions
21
auth/auth.go
21
auth/auth.go
|
@ -18,12 +18,9 @@ type Email string
|
||||||
type DeviceId string
|
type DeviceId string
|
||||||
type Password string
|
type Password string
|
||||||
type AuthTokenString string
|
type AuthTokenString string
|
||||||
type DownloadKey string
|
|
||||||
|
|
||||||
type AuthScope string
|
type AuthScope string
|
||||||
|
|
||||||
const ScopeFull = AuthScope("*")
|
const ScopeFull = AuthScope("*")
|
||||||
const ScopeGetWalletState = AuthScope("get-wallet-state")
|
|
||||||
|
|
||||||
// For test stubs
|
// For test stubs
|
||||||
type AuthInterface interface {
|
type AuthInterface interface {
|
||||||
|
@ -64,20 +61,10 @@ func (a *Auth) NewToken(userId UserId, deviceId DeviceId, scope AuthScope) (*Aut
|
||||||
|
|
||||||
// NOTE - not stubbing methods of structs like this. more convoluted than it's worth right now
|
// NOTE - not stubbing methods of structs like this. more convoluted than it's worth right now
|
||||||
func (at *AuthToken) ScopeValid(required AuthScope) bool {
|
func (at *AuthToken) ScopeValid(required AuthScope) bool {
|
||||||
// So far the only two scopes issued
|
// So far the only scope issued. Used to have more, didn't want to delete
|
||||||
if at.Scope == ScopeFull {
|
// this feature yet in case we add more again. We'll delete it if it's of
|
||||||
return true
|
// no use and ends up complicating anything.
|
||||||
}
|
return at.Scope == ScopeFull
|
||||||
if at.Scope == ScopeGetWalletState && required == ScopeGetWalletState {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d DownloadKey) Obfuscate() string {
|
|
||||||
// TODO KDF instead
|
|
||||||
hash := sha256.Sum256([]byte(d))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Password) Obfuscate() string {
|
func (p Password) Obfuscate() string {
|
||||||
|
|
|
@ -6,13 +6,6 @@ import (
|
||||||
|
|
||||||
// Test stubs for now
|
// Test stubs for now
|
||||||
|
|
||||||
func TestAuthSignaturePass(t *testing.T) {
|
|
||||||
t.Fatalf("Test me: Valid siganture passes")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAuthSignatureFail(t *testing.T) {
|
|
||||||
t.Fatalf("Test me: Valid siganture fails")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAuthNewTokenSuccess(t *testing.T) {
|
func TestAuthNewTokenSuccess(t *testing.T) {
|
||||||
t.Fatalf("Test me: New token passes. Different scopes etc.")
|
t.Fatalf("Test me: New token passes. Different scopes etc.")
|
||||||
|
@ -24,19 +17,8 @@ func TestAuthNewTokenFail(t *testing.T) {
|
||||||
|
|
||||||
func TestAuthScopeValid(t *testing.T) {
|
func TestAuthScopeValid(t *testing.T) {
|
||||||
t.Fatalf("Test me: Scope Valid tests")
|
t.Fatalf("Test me: Scope Valid tests")
|
||||||
/*
|
|
||||||
authToken.Scope = "get-wallet-state"; authToken.ScopeValid("*")
|
|
||||||
authToken.Scope = "get-wallet-state"; authToken.ScopeValid("get-wallet-state")
|
|
||||||
|
|
||||||
// even things that haven't been defined yet, for simplicity
|
|
||||||
authToken.Scope = "bananas"; authToken.ScopeValid("*")
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuthScopeInvalid(t *testing.T) {
|
func TestAuthScopeInvalid(t *testing.T) {
|
||||||
t.Fatalf("Test me: Scope Invalid tests")
|
t.Fatalf("Test me: Scope Invalid tests")
|
||||||
/*
|
|
||||||
authToken.Scope = "get-wallet-state"; authToken.ScopeValid("bananas")
|
|
||||||
authToken.Scope = "bananas"; authToken.ScopeValid("get-wallet-state")
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,18 +22,6 @@ func (r *AuthFullRequest) validate() bool {
|
||||||
r.Password != auth.Password(""))
|
r.Password != auth.Password(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthForGetWalletStateRequest struct {
|
|
||||||
Email auth.Email `json:"email"`
|
|
||||||
DownloadKey auth.DownloadKey `json:"downloadKey"`
|
|
||||||
DeviceId auth.DeviceId `json:"deviceId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *AuthForGetWalletStateRequest) validate() bool {
|
|
||||||
return (r.Email != "" &&
|
|
||||||
r.DownloadKey != auth.DownloadKey("") &&
|
|
||||||
r.DeviceId != "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getAuthTokenFull(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) getAuthTokenFull(w http.ResponseWriter, req *http.Request) {
|
||||||
var authRequest AuthFullRequest
|
var authRequest AuthFullRequest
|
||||||
if !getPostData(w, req, &authRequest) {
|
if !getPostData(w, req, &authRequest) {
|
||||||
|
|
|
@ -157,14 +157,3 @@ func TestServerValidateAuthFullRequest(t *testing.T) {
|
||||||
t.Fatalf("Test me: Implement and test AuthFullRequest.validate()")
|
t.Fatalf("Test me: Implement and test AuthFullRequest.validate()")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerValidateAuthForGetWalletStateRequest(t *testing.T) {
|
|
||||||
t.Fatalf("Test me: Implement and test AuthForGetWalletStateRequest.validate()")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServerAuthHandlerForGetWalletStateSuccess(t *testing.T) {
|
|
||||||
t.Fatalf("Test me: getAuthTokenForGetWalletState success")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServerAuthHandlerForGetWalletStateErrors(t *testing.T) {
|
|
||||||
t.Fatalf("Test me: getAuthTokenForGetWalletState failure")
|
|
||||||
}
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (s *Server) getWalletState(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authToken := s.checkAuth(w, token, auth.ScopeGetWalletState)
|
authToken := s.checkAuth(w, token, auth.ScopeFull)
|
||||||
|
|
||||||
if authToken == nil {
|
if authToken == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -204,9 +204,9 @@ func (s *Store) SaveToken(token *auth.AuthToken) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////
|
//////////////////
|
||||||
// Wallet State / Download Key //
|
// Wallet State //
|
||||||
/////////////////////////////////
|
//////////////////
|
||||||
|
|
||||||
func (s *Store) GetWalletState(userId auth.UserId) (walletStateJson string, hmac wallet.WalletStateHmac, err error) {
|
func (s *Store) GetWalletState(userId auth.UserId) (walletStateJson string, hmac wallet.WalletStateHmac, err error) {
|
||||||
rows, err := s.db.Query(
|
rows, err := s.db.Query(
|
||||||
|
|
|
@ -4,7 +4,6 @@ from pprint import pprint
|
||||||
|
|
||||||
BASE_URL = 'http://localhost:8090'
|
BASE_URL = 'http://localhost:8090'
|
||||||
AUTH_FULL_URL = BASE_URL + '/auth/full'
|
AUTH_FULL_URL = BASE_URL + '/auth/full'
|
||||||
AUTH_GET_WALLET_STATE_URL = BASE_URL + '/auth/get-wallet-state'
|
|
||||||
REGISTER_URL = BASE_URL + '/signup'
|
REGISTER_URL = BASE_URL + '/signup'
|
||||||
WALLET_STATE_URL = BASE_URL + '/wallet-state'
|
WALLET_STATE_URL = BASE_URL + '/wallet-state'
|
||||||
|
|
||||||
|
@ -98,23 +97,6 @@ class Client():
|
||||||
return
|
return
|
||||||
print ("Registered")
|
print ("Registered")
|
||||||
|
|
||||||
def get_download_auth_token(self, email, password):
|
|
||||||
body = json.dumps({
|
|
||||||
'email': email,
|
|
||||||
'password': create_login_password(password),
|
|
||||||
'deviceId': self.device_id,
|
|
||||||
})
|
|
||||||
response = requests.post(AUTH_GET_WALLET_STATE_URL, body)
|
|
||||||
if response.status_code != 200:
|
|
||||||
print ('Error', response.status_code)
|
|
||||||
print (response.content)
|
|
||||||
return
|
|
||||||
self.auth_token = json.loads(response.content)['token']
|
|
||||||
print ("Got auth token: ", self.auth_token)
|
|
||||||
|
|
||||||
self.email = email
|
|
||||||
self.root_password = root_password
|
|
||||||
|
|
||||||
# TODO - Rename to get_auth_token. same in go. Remember to grep, gotta change
|
# TODO - Rename to get_auth_token. same in go. Remember to grep, gotta change
|
||||||
# it in README as well.
|
# it in README as well.
|
||||||
def get_full_auth_token(self):
|
def get_full_auth_token(self):
|
||||||
|
|
Loading…
Reference in a new issue