mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-21 03:24:13 -05:00
Merge pull request #1635 from willhite/js
Forward all query parameters when calling remote server api.
This commit is contained in:
@@ -335,7 +335,7 @@ func (bhcs *httpBatchStore) requestRoot(method string, current, last hash.Hash)
|
||||
u.Path = httprouter.CleanPath(bhcs.host.Path + constants.RootPath)
|
||||
if method == "POST" {
|
||||
d.Exp.False(current.IsEmpty())
|
||||
params := url.Values{}
|
||||
params := u.Query()
|
||||
params.Add("last", last.String())
|
||||
params.Add("current", current.String())
|
||||
u.RawQuery = params.Encode()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package datas
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -10,10 +11,12 @@ import (
|
||||
"github.com/attic-labs/noms/constants"
|
||||
"github.com/attic-labs/noms/hash"
|
||||
"github.com/attic-labs/noms/types"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/attic-labs/testify/suite"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
const testAuthToken = "aToken123"
|
||||
|
||||
func TestHTTPBatchStore(t *testing.T) {
|
||||
suite.Run(t, &HTTPBatchStoreSuite{})
|
||||
}
|
||||
@@ -76,6 +79,24 @@ func newHTTPBatchStoreForTest(cs chunks.ChunkStore) *httpBatchStore {
|
||||
return hcs
|
||||
}
|
||||
|
||||
func newAuthenticatingHTTPBatchStoreForTest(suite *HTTPBatchStoreSuite, hostUrl string) *httpBatchStore {
|
||||
authenticate := func(req *http.Request) {
|
||||
suite.Equal(testAuthToken, req.URL.Query().Get("access_token"))
|
||||
}
|
||||
|
||||
serv := inlineServer{httprouter.New()}
|
||||
serv.POST(
|
||||
constants.RootPath,
|
||||
func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
authenticate(req)
|
||||
HandleRootPost(w, req, ps, suite.cs)
|
||||
},
|
||||
)
|
||||
hcs := newHTTPBatchStore(hostUrl, "")
|
||||
hcs.httpClient = serv
|
||||
return hcs
|
||||
}
|
||||
|
||||
func (suite *HTTPBatchStoreSuite) TearDownTest() {
|
||||
suite.store.Close()
|
||||
suite.cs.Close()
|
||||
@@ -180,7 +201,15 @@ func (suite *HTTPBatchStoreSuite) TestRoot() {
|
||||
|
||||
func (suite *HTTPBatchStoreSuite) TestUpdateRoot() {
|
||||
c := chunks.NewChunk([]byte("abc"))
|
||||
suite.True(suite.store.UpdateRoot(c.Hash(), hash.Hash{}))
|
||||
suite.True(suite.cs.UpdateRoot(c.Hash(), hash.Hash{}))
|
||||
suite.Equal(c.Hash(), suite.store.Root())
|
||||
}
|
||||
|
||||
func (suite *HTTPBatchStoreSuite) TestUpdateRootWithParams() {
|
||||
u := fmt.Sprintf("http://localhost:9000?access_token=%s&other=19", testAuthToken)
|
||||
store := newAuthenticatingHTTPBatchStoreForTest(suite, u)
|
||||
c := chunks.NewChunk([]byte("abc"))
|
||||
suite.True(store.UpdateRoot(c.Hash(), hash.Hash{}))
|
||||
suite.Equal(c.Hash(), suite.cs.Root())
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@attic/noms",
|
||||
"version": "40.0.0",
|
||||
"version": "41.0.0",
|
||||
"description": "Noms JS SDK",
|
||||
"repository": "https://github.com/attic-labs/noms",
|
||||
"main": "dist/commonjs/noms.js",
|
||||
|
||||
@@ -103,7 +103,8 @@ export class Delegate {
|
||||
}
|
||||
|
||||
async updateRoot(current: Hash, last: Hash): Promise<boolean> {
|
||||
const params = `?current=${current}&last=${last}`;
|
||||
const ch = this._rpc.root.indexOf('?') >= 0 ? '&' : '?';
|
||||
const params = `${ch}current=${current}&last=${last}`;
|
||||
try {
|
||||
await fetchText(this._rpc.root + params, {method: 'POST'});
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user