commit ec4075a3a54d7e154b171ba248f57900f6622c9a
parent 9669c7f6441a25f0c5a3e9ffebbeff96b486a26d
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Thu, 7 Jul 2022 00:13:45 +0200
more tests
Diffstat:
3 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,6 @@
+.gitignore
+go.sum
+**/validation_code
+taldir-server
+taldir-cli
+gana
diff --git a/cmd/taldir-server/main_test.go b/cmd/taldir-server/main_test.go
@@ -26,6 +26,9 @@ import (
"net/http/httptest"
"crypto/sha512"
"bytes"
+ "strings"
+ "io/ioutil"
+ "log"
"taler.net/taldir/cmd/taldir-server"
"taler.net/taldir/util"
)
@@ -73,14 +76,30 @@ func executeRequest(req *http.Request) *httptest.ResponseRecorder {
}
func TestRegisterRequest(s *testing.T) {
- t.ClearDatabase()
+ t.ClearDatabase()
- req, _ := http.NewRequest("POST", "/register/test", bytes.NewBuffer(validRegisterRequest))
- response := executeRequest(req)
+ 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)
- }
+ 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)
+ }
}
-
-
diff --git a/test.sh b/test.sh
@@ -1,15 +0,0 @@
-#!/bin/bash
-# New request
-PUBKEY="000G006XE97PTWV3B7AJNCRQZA6BF26HPV3XZ07293FMY7KD4181946A90"
-curl -v localhost:11000/register/test --data "{\"address\": \"abc@test\", \"public_key\": \"${PUBKEY}\", \"inbox_url\": \"myinbox@xyz\", \"duration\": 23}"
-# Read validation code from tempfile
-CODE=`cat validation_code`
-H_ADDRESS=`echo -n abc@test | openssl dgst -binary -sha512 | gnunet-base32`
-echo "Code: $CODE; Address: $H_ADDRESS"
-# Validate
-# echo localhost:11000/register/$H_ADDRESS/$CODE
-SOLUTION=$(./taldir-cli -s -c ${CODE} -p ${PUBKEY})
-echo "Solution: $SOLUTION"
-curl -v localhost:11000/$H_ADDRESS --data "{\"solution\": \"${SOLUTION}\"}"
-# Get mapping
-curl -v localhost:11000/$H_ADDRESS