From 41721a8f70cd87fd82486babc512a14642c93992 Mon Sep 17 00:00:00 2001 From: Daniel Krol Date: Tue, 7 Jun 2022 18:15:46 -0400 Subject: [PATCH] Delete some things we don't need anymore --- auth/auth.go | 21 ++++----------------- auth/auth_test.go | 18 ------------------ server/auth.go | 12 ------------ server/auth_test.go | 11 ----------- server/wallet_state.go | 2 +- store/store.go | 6 +++--- test_client/test_client.py | 18 ------------------ 7 files changed, 8 insertions(+), 80 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index a62f793..fdaaf7e 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -18,12 +18,9 @@ type Email string type DeviceId string type Password string type AuthTokenString string -type DownloadKey string - type AuthScope string const ScopeFull = AuthScope("*") -const ScopeGetWalletState = AuthScope("get-wallet-state") // For test stubs 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 func (at *AuthToken) ScopeValid(required AuthScope) bool { - // So far the only two scopes issued - if at.Scope == ScopeFull { - return true - } - 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[:]) + // So far the only scope issued. Used to have more, didn't want to delete + // this feature yet in case we add more again. We'll delete it if it's of + // no use and ends up complicating anything. + return at.Scope == ScopeFull } func (p Password) Obfuscate() string { diff --git a/auth/auth_test.go b/auth/auth_test.go index a304934..5b95b0e 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -6,13 +6,6 @@ import ( // 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) { t.Fatalf("Test me: New token passes. Different scopes etc.") @@ -24,19 +17,8 @@ func TestAuthNewTokenFail(t *testing.T) { func TestAuthScopeValid(t *testing.T) { 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) { t.Fatalf("Test me: Scope Invalid tests") - /* - authToken.Scope = "get-wallet-state"; authToken.ScopeValid("bananas") - authToken.Scope = "bananas"; authToken.ScopeValid("get-wallet-state") - */ } diff --git a/server/auth.go b/server/auth.go index 187d7c9..593c268 100644 --- a/server/auth.go +++ b/server/auth.go @@ -22,18 +22,6 @@ func (r *AuthFullRequest) validate() bool { 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) { var authRequest AuthFullRequest if !getPostData(w, req, &authRequest) { diff --git a/server/auth_test.go b/server/auth_test.go index 0d71dba..00faad2 100644 --- a/server/auth_test.go +++ b/server/auth_test.go @@ -157,14 +157,3 @@ func TestServerValidateAuthFullRequest(t *testing.T) { 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") -} diff --git a/server/wallet_state.go b/server/wallet_state.go index 98a4f82..8f6aa9e 100644 --- a/server/wallet_state.go +++ b/server/wallet_state.go @@ -67,7 +67,7 @@ func (s *Server) getWalletState(w http.ResponseWriter, req *http.Request) { return } - authToken := s.checkAuth(w, token, auth.ScopeGetWalletState) + authToken := s.checkAuth(w, token, auth.ScopeFull) if authToken == nil { return diff --git a/store/store.go b/store/store.go index 30c452c..44e7880 100644 --- a/store/store.go +++ b/store/store.go @@ -204,9 +204,9 @@ func (s *Store) SaveToken(token *auth.AuthToken) (err error) { return } -///////////////////////////////// -// Wallet State / Download Key // -///////////////////////////////// +////////////////// +// Wallet State // +////////////////// func (s *Store) GetWalletState(userId auth.UserId) (walletStateJson string, hmac wallet.WalletStateHmac, err error) { rows, err := s.db.Query( diff --git a/test_client/test_client.py b/test_client/test_client.py index d4fd05a..c7d00df 100755 --- a/test_client/test_client.py +++ b/test_client/test_client.py @@ -4,7 +4,6 @@ from pprint import pprint BASE_URL = 'http://localhost:8090' AUTH_FULL_URL = BASE_URL + '/auth/full' -AUTH_GET_WALLET_STATE_URL = BASE_URL + '/auth/get-wallet-state' REGISTER_URL = BASE_URL + '/signup' WALLET_STATE_URL = BASE_URL + '/wallet-state' @@ -98,23 +97,6 @@ class Client(): return 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 # it in README as well. def get_full_auth_token(self):