diff options
| -rw-r--r-- | go.mod | 2 | ||||
| -rwxr-xr-x | integration/test.sh | 16 | ||||
| -rw-r--r-- | pkg/instance/handler_test.go | 56 | ||||
| -rw-r--r-- | pkg/instance/instance.go | 12 | 
4 files changed, 31 insertions, 55 deletions
| @@ -2,6 +2,8 @@ module git.sigsum.org/log-go  go 1.15 +replace git.sigsum.org/sigsum-go => /home/rgdd/src/git.sigsum.org/sigsum-go +  require (  	git.sigsum.org/sigsum-go v0.0.4  	github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b diff --git a/integration/test.sh b/integration/test.sh index e22857f..ec0d39e 100755 --- a/integration/test.sh +++ b/integration/test.sh @@ -285,12 +285,8 @@ function test_cosigned_tree_head() {  function test_inclusion_proof() {  	desc="POST get-inclusion-proof (tree_size $1, data \"$2\", index $3)"  	signature=$(echo $2 | sigsum-debug leaf sign -k $cli_priv -h $ssrv_shard_start) -	echo "tree_size=$1" > $log_dir/req -	echo "leaf_hash=$(echo $2 | -		sigsum-debug leaf hash -k $cli_key_hash -s $signature -h $ssrv_shard_start)" >> $log_dir/req -	cat $log_dir/req | -		curl -s -w "%{http_code}" --data-binary @- $log_url/get-inclusion-proof \ -		>$log_dir/rsp +	leaf_hash=$(echo $2 | sigsum-debug leaf hash -k $cli_key_hash -s $signature -h $ssrv_shard_start) +	curl -s -w "%{http_code}" $log_url/get-inclusion-proof/$1/$leaf_hash >$log_dir/rsp  	if [[ $(status_code) != 200 ]]; then  		fail "$desc: http status code $(status_code)" @@ -313,9 +309,7 @@ function test_inclusion_proof() {  function test_consistency_proof() {  	desc="POST get-consistency-proof (old_size $1, new_size $2)" -	printf "old_size=$1\nnew_size=$2\n" | -		curl -s -w "%{http_code}" --data-binary @- $log_url/get-consistency-proof \ -		>$log_dir/rsp +	curl -s -w "%{http_code}" $log_url/get-consistency-proof/$1/$2 >$log_dir/rsp  	if [[ $(status_code) != 200 ]]; then  		fail "$desc: http status code $(status_code)" @@ -333,9 +327,7 @@ function test_consistency_proof() {  function test_get_leaf() {  	desc="GET get-leaves (data \"$1\", index $2)" -	printf "start_size=$2\nend_size=$2\n" | -		curl -s -w "%{http_code}" --data-binary @- $log_url/get-leaves \ -		>$log_dir/rsp +	curl -s -w "%{http_code}" $log_url/get-leaves/$2/$2 >$log_dir/rsp  	if [[ $(status_code) != 200 ]]; then  		fail "$desc: http status code $(status_code)" diff --git a/pkg/instance/handler_test.go b/pkg/instance/handler_test.go index 46a99d5..b3af666 100644 --- a/pkg/instance/handler_test.go +++ b/pkg/instance/handler_test.go @@ -420,15 +420,9 @@ func TestGetTreeCosigned(t *testing.T) {  }  func TestGetConsistencyProof(t *testing.T) { -	buf := func(oldSize, newSize int) io.Reader { -		return bytes.NewBufferString(fmt.Sprintf("%s=%d\n%s=%d\n", -			"old_size", oldSize, -			"new_size", newSize, -		)) -	}  	for _, table := range []struct {  		description string -		ascii       io.Reader               // buffer used to populate HTTP request +		params      string                  // params is the query's url params  		expect      bool                    // set if a mock answer is expected  		rsp         *types.ConsistencyProof // consistency proof from Trillian client  		err         error                   // error from Trillian client @@ -436,29 +430,29 @@ func TestGetConsistencyProof(t *testing.T) {  	}{  		{  			description: "invalid: bad request (parser error)", -			ascii:       bytes.NewBufferString("key=value\n"), +			params:      "a/1",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: bad request (OldSize is zero)", -			ascii:       buf(0, 1), +			params:      "0/1",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: bad request (OldSize > NewSize)", -			ascii:       buf(2, 1), +			params:      "2/1",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: backend failure", -			ascii:       buf(1, 2), +			params:      "1/2",  			expect:      true,  			err:         fmt.Errorf("something went wrong"),  			wantCode:    http.StatusInternalServerError,  		},  		{  			description: "valid", -			ascii:       buf(1, 2), +			params:      "1/2",  			expect:      true,  			rsp: &types.ConsistencyProof{  				OldSize: 1, @@ -485,7 +479,7 @@ func TestGetConsistencyProof(t *testing.T) {  			// Create HTTP request  			url := types.EndpointGetConsistencyProof.Path("http://example.com", i.Prefix) -			req, err := http.NewRequest("POST", url, table.ascii) +			req, err := http.NewRequest(http.MethodGet, url+table.params, nil)  			if err != nil {  				t.Fatalf("must create http request: %v", err)  			} @@ -501,15 +495,9 @@ func TestGetConsistencyProof(t *testing.T) {  }  func TestGetInclusionProof(t *testing.T) { -	buf := func(hash *types.Hash, treeSize int) io.Reader { -		return bytes.NewBufferString(fmt.Sprintf("%s=%x\n%s=%d\n", -			"leaf_hash", hash[:], -			"tree_size", treeSize, -		)) -	}  	for _, table := range []struct {  		description string -		ascii       io.Reader             // buffer used to populate HTTP request +		params      string                // params is the query's url params  		expect      bool                  // set if a mock answer is expected  		rsp         *types.InclusionProof // inclusion proof from Trillian client  		err         error                 // error from Trillian client @@ -517,24 +505,24 @@ func TestGetInclusionProof(t *testing.T) {  	}{  		{  			description: "invalid: bad request (parser error)", -			ascii:       bytes.NewBufferString("key=value\n"), +			params:      "a/0000000000000000000000000000000000000000000000000000000000000000",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: bad request (no proof for tree size)", -			ascii:       buf(types.HashFn([]byte{}), 1), +			params:      "1/0000000000000000000000000000000000000000000000000000000000000000",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: backend failure", -			ascii:       buf(types.HashFn([]byte{}), 2), +			params:      "2/0000000000000000000000000000000000000000000000000000000000000000",  			expect:      true,  			err:         fmt.Errorf("something went wrong"),  			wantCode:    http.StatusInternalServerError,  		},  		{  			description: "valid", -			ascii:       buf(types.HashFn([]byte{}), 2), +			params:      "2/0000000000000000000000000000000000000000000000000000000000000000",  			expect:      true,  			rsp: &types.InclusionProof{  				TreeSize:  2, @@ -561,7 +549,7 @@ func TestGetInclusionProof(t *testing.T) {  			// Create HTTP request  			url := types.EndpointGetInclusionProof.Path("http://example.com", i.Prefix) -			req, err := http.NewRequest("POST", url, table.ascii) +			req, err := http.NewRequest(http.MethodGet, url+table.params, nil)  			if err != nil {  				t.Fatalf("must create http request: %v", err)  			} @@ -577,15 +565,9 @@ func TestGetInclusionProof(t *testing.T) {  }  func TestGetLeaves(t *testing.T) { -	buf := func(startSize, endSize int64) io.Reader { -		return bytes.NewBufferString(fmt.Sprintf("%s=%d\n%s=%d\n", -			"start_size", startSize, -			"end_size", endSize, -		)) -	}  	for _, table := range []struct {  		description string -		ascii       io.Reader     // buffer used to populate HTTP request +		params      string        // params is the query's url params  		expect      bool          // set if a mock answer is expected  		rsp         *types.Leaves // list of leaves from Trillian client  		err         error         // error from Trillian client @@ -593,24 +575,24 @@ func TestGetLeaves(t *testing.T) {  	}{  		{  			description: "invalid: bad request (parser error)", -			ascii:       bytes.NewBufferString("key=value\n"), +			params:      "a/1",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: bad request (StartSize > EndSize)", -			ascii:       buf(1, 0), +			params:      "1/0",  			wantCode:    http.StatusBadRequest,  		},  		{  			description: "invalid: backend failure", -			ascii:       buf(0, 0), +			params:      "0/0",  			expect:      true,  			err:         fmt.Errorf("something went wrong"),  			wantCode:    http.StatusInternalServerError,  		},  		{  			description: "valid: one more entry than the configured MaxRange", -			ascii:       buf(0, testConfig.MaxRange), // query will be pruned +			params:      fmt.Sprintf("%d/%d", 0, testConfig.MaxRange), // query will be pruned  			expect:      true,  			rsp: func() *types.Leaves {  				var list types.Leaves @@ -644,7 +626,7 @@ func TestGetLeaves(t *testing.T) {  			// Create HTTP request  			url := types.EndpointGetLeaves.Path("http://example.com", i.Prefix) -			req, err := http.NewRequest("POST", url, table.ascii) +			req, err := http.NewRequest(http.MethodGet, url+table.params, nil)  			if err != nil {  				t.Fatalf("must create http request: %v", err)  			} diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index fe05b6a..77f2e5b 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -45,9 +45,9 @@ func (i *Instance) Handlers() []Handler {  		Handler{Instance: i, Handler: getTreeHeadToCosign, Endpoint: types.EndpointGetTreeHeadToSign, Method: http.MethodGet}, // XXX: ToCosign  		Handler{Instance: i, Handler: getTreeHeadCosigned, Endpoint: types.EndpointGetTreeHeadCosigned, Method: http.MethodGet},  		Handler{Instance: i, Handler: getCheckpoint, Endpoint: types.Endpoint("get-checkpoint"), Method: http.MethodGet}, -		Handler{Instance: i, Handler: getConsistencyProof, Endpoint: types.EndpointGetConsistencyProof, Method: http.MethodPost}, -		Handler{Instance: i, Handler: getInclusionProof, Endpoint: types.EndpointGetInclusionProof, Method: http.MethodPost}, -		Handler{Instance: i, Handler: getLeaves, Endpoint: types.EndpointGetLeaves, Method: http.MethodPost}, +		Handler{Instance: i, Handler: getConsistencyProof, Endpoint: types.EndpointGetConsistencyProof, Method: http.MethodGet}, +		Handler{Instance: i, Handler: getInclusionProof, Endpoint: types.EndpointGetInclusionProof, Method: http.MethodGet}, +		Handler{Instance: i, Handler: getLeaves, Endpoint: types.EndpointGetLeaves, Method: http.MethodGet},  	}  } @@ -94,7 +94,7 @@ func (i *Instance) cosignatureRequestFromHTTP(r *http.Request) (*requests.Cosign  func (i *Instance) consistencyProofRequestFromHTTP(r *http.Request) (*requests.ConsistencyProof, error) {  	var req requests.ConsistencyProof -	if err := req.FromASCII(r.Body); err != nil { +	if err := req.FromURL(r.URL.Path); err != nil {  		return nil, fmt.Errorf("FromASCII: %v", err)  	}  	if req.OldSize < 1 { @@ -108,7 +108,7 @@ func (i *Instance) consistencyProofRequestFromHTTP(r *http.Request) (*requests.C  func (i *Instance) inclusionProofRequestFromHTTP(r *http.Request) (*requests.InclusionProof, error) {  	var req requests.InclusionProof -	if err := req.FromASCII(r.Body); err != nil { +	if err := req.FromURL(r.URL.Path); err != nil {  		return nil, fmt.Errorf("FromASCII: %v", err)  	}  	if req.TreeSize < 2 { @@ -121,7 +121,7 @@ func (i *Instance) inclusionProofRequestFromHTTP(r *http.Request) (*requests.Inc  func (i *Instance) leavesRequestFromHTTP(r *http.Request) (*requests.Leaves, error) {  	var req requests.Leaves -	if err := req.FromASCII(r.Body); err != nil { +	if err := req.FromURL(r.URL.Path); err != nil {  		return nil, fmt.Errorf("FromASCII: %v", err)  	} | 
