taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit cb3e901f691250fa4fbadf9e5edcbe4722c92812
parent c89cd448763710db0fc287131cccb785dc3f78aa
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Thu,  7 Jul 2022 17:02:21 +0200

fix wrong existing reg detection; test reregistrations

Diffstat:
Mcmd/taldir-server/main_test.go | 49++++++++++++++++++++++++++++++++++++++++++++++++-
Mcmd/taldir-server/taldir.go | 5+++--
Mcmd/taldir-server/testdata/taldir-test.conf | 2+-
Mtaldir.conf | 2+-
4 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/cmd/taldir-server/main_test.go b/cmd/taldir-server/main_test.go @@ -40,10 +40,20 @@ var validRegisterRequest = []byte(` "address": "abc@test", "public_key": "000G006XE97PTWV3B7AJNCRQZA6BF26HPV3XZ07293FMY7KD4181946A90", "inbox_url": "myinbox@xyz", - "duration": 23 + "duration": 23000000 } `) +var validRegisterRequestShort = []byte(` + { + "address": "abc@test", + "public_key": "000G006XE97PTWV3B7AJNCRQZA6BF26HPV3XZ07293FMY7KD4181946A90", + "inbox_url": "myinbox@xyz", + "duration": 10000000 + } +`) + + func TestMain(m *testing.M) { t.Initialize("testdata/taldir-test.conf", true) code := m.Run() @@ -104,6 +114,43 @@ func TestRegisterRequest(s *testing.T) { } } +func TestReRegisterRequest(s *testing.T) { + t.ClearDatabase() + + req, _ := http.NewRequest("POST", "/register/test", bytes.NewBuffer(validRegisterRequest)) + response := executeRequest(req) + + if http.StatusAccepted != response.Code { + s.Errorf("Expected response code %d. Got %d\n", http.StatusAccepted, response.Code) + } + file, err := os.Open("validation_code") + if err != nil { + s.Errorf("No validation code file found!\n") + } + code, err := ioutil.ReadAll(file) + if err != nil { + s.Errorf("Error reading validation code file contents!\n") + } + log.Printf("Got code: %s\n", code) + h_addr := getHAddress("abc@test") + trimCode := strings.Trim(string(code), " \r\n") + solution := util.GenerateSolution("000G006XE97PTWV3B7AJNCRQZA6BF26HPV3XZ07293FMY7KD4181946A90", trimCode) + solutionJSON := "{\"solution\": \"" + solution + "\"}" + req, _ = http.NewRequest("POST", "/" + h_addr, bytes.NewBuffer([]byte(solutionJSON))) + response = executeRequest(req) + if http.StatusNoContent != response.Code { + s.Errorf("Expected response code %d. Got %d\n", http.StatusNoContent, response.Code) + } + req, _ = http.NewRequest("POST", "/register/test", bytes.NewBuffer(validRegisterRequestShort)) + response = executeRequest(req) + + if http.StatusOK != response.Code { + s.Errorf("Expected response code %d. Got %d\n", http.StatusOK, response.Code) + } + +} + + func TestRegisterRequestWrongPubkey(s *testing.T) { t.ClearDatabase() diff --git a/cmd/taldir-server/taldir.go b/cmd/taldir-server/taldir.go @@ -352,7 +352,8 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request){ // is still valid and the duration is not extended. hs_address := saltHAddress(validation.HAddress, t.Salt) err = t.Db.First(&entry, "hs_address = ?", hs_address).Error - if err != nil { + if err == nil { + log.Println("Entry for this address already exists..") lastRegValidity := entry.RegisteredAt + entry.Duration requestedValidity := time.Now().UnixMicro() + req.Duration earliestReRegistration := entry.RegisteredAt + t.RequestFrequency @@ -623,7 +624,7 @@ func (t *Taldir) Initialize(cfgfile string, clearDb bool) { if "" == t.Salt { t.Salt = t.Cfg.Section("taldir").Key("salt").MustString("ChangeMe") } - t.RequestFrequency = t.Cfg.Section("taldir").Key("request_frequency").MustInt64(1000) + t.RequestFrequency = t.Cfg.Section("taldir").Key("request_frequency_microseconds").MustInt64(1000) t.setupHandlers() } diff --git a/cmd/taldir-server/testdata/taldir-test.conf b/cmd/taldir-server/testdata/taldir-test.conf @@ -5,7 +5,7 @@ host = "https://taldir.net" bind_to = "localhost:11000" salt = "ChangeMe" monthly_fee = KUDOS:1 -request_frequency = 3 +request_frequency_microseconds = 10 validation_landing = testdata/templates/validation_landing.html [taldir-test] diff --git a/taldir.conf b/taldir.conf @@ -5,7 +5,7 @@ host = "https://taldir.net" bind_to = "localhost:11000" salt = "ChangeMe" monthly_fee = KUDOS:1 -request_frequency = 3 +request_frequency_microseconds = 5000000 default_doc_filetype = text/markdown default_doc_lang = en-US default_tos_path = terms/