|
|
|
@ -82,6 +82,11 @@ var DefaultFalseResp = milvuspb.BoolResponse{
|
|
|
|
|
Value: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDefaultRootPassword() string {
|
|
|
|
|
paramtable.Init()
|
|
|
|
|
return paramtable.Get().CommonCfg.DefaultRootPassword.GetValue()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func versional(path string) string {
|
|
|
|
|
return URIPrefixV1 + path
|
|
|
|
|
}
|
|
|
|
@ -128,7 +133,7 @@ func genAuthMiddleWare(needAuth bool) gin.HandlerFunc {
|
|
|
|
|
username, password, ok := ParseUsernamePassword(c)
|
|
|
|
|
if !ok {
|
|
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{HTTPReturnCode: merr.Code(merr.ErrNeedAuthenticate), HTTPReturnMessage: merr.ErrNeedAuthenticate.Error()})
|
|
|
|
|
} else if username == util.UserRoot && password != util.DefaultRootPassword {
|
|
|
|
|
} else if username == util.UserRoot && password != getDefaultRootPassword() {
|
|
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{HTTPReturnCode: merr.Code(merr.ErrNeedAuthenticate), HTTPReturnMessage: merr.ErrNeedAuthenticate.Error()})
|
|
|
|
|
} else {
|
|
|
|
|
c.Set(ContextUsername, username)
|
|
|
|
@ -183,7 +188,7 @@ func TestVectorAuthenticate(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("root's password correct", func(t *testing.T) {
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, versional(VectorCollectionsPath), nil)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -237,7 +242,7 @@ func TestVectorListCollection(t *testing.T) {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(tt.mp, true)
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, versional(VectorCollectionsPath), nil)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -301,7 +306,7 @@ func TestVectorCollectionsDescribe(t *testing.T) {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(tt.mp, true)
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, versional(VectorCollectionsDescribePath)+"?collectionName="+DefaultCollectionName, nil)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -315,7 +320,7 @@ func TestVectorCollectionsDescribe(t *testing.T) {
|
|
|
|
|
t.Run("need collectionName", func(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(mocks.NewMockProxy(t), true)
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, versional(VectorCollectionsDescribePath)+"?"+DefaultCollectionName, nil)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -384,7 +389,7 @@ func TestVectorCreateCollection(t *testing.T) {
|
|
|
|
|
jsonBody := []byte(`{"collectionName": "` + DefaultCollectionName + `", "dimension": 2}`)
|
|
|
|
|
bodyReader := bytes.NewReader(jsonBody)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorCollectionsCreatePath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -441,7 +446,7 @@ func TestVectorDropCollection(t *testing.T) {
|
|
|
|
|
jsonBody := []byte(`{"collectionName": "` + DefaultCollectionName + `"}`)
|
|
|
|
|
bodyReader := bytes.NewReader(jsonBody)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorCollectionsDropPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -517,7 +522,7 @@ func TestQuery(t *testing.T) {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(tt.mp, true)
|
|
|
|
|
for _, req := range reqs {
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -602,7 +607,7 @@ func TestDelete(t *testing.T) {
|
|
|
|
|
jsonBody := []byte(`{"collectionName": "` + DefaultCollectionName + `" , "id": [1,2,3]}`)
|
|
|
|
|
bodyReader := bytes.NewReader(jsonBody)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorDeletePath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -634,7 +639,7 @@ func TestDeleteForFilter(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(mp, true)
|
|
|
|
|
bodyReader := bytes.NewReader(jsonBody)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorDeletePath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -726,7 +731,7 @@ func TestInsert(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(tt.mp, true)
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -747,7 +752,7 @@ func TestInsert(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(mp, true)
|
|
|
|
|
bodyReader := bytes.NewReader([]byte(`{"collectionName": "` + DefaultCollectionName + `", "data": {}}`))
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -788,7 +793,7 @@ func TestInsertForDataType(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -813,7 +818,7 @@ func TestInsertForDataType(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -856,7 +861,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -887,7 +892,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -918,7 +923,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
req.Header.Set(HTTPHeaderAllowInt64, "true")
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
@ -950,7 +955,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
req.Header.Set(HTTPHeaderAllowInt64, "true")
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
@ -983,7 +988,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -1014,7 +1019,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -1045,7 +1050,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorInsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
req.Header.Set(HTTPHeaderAllowInt64, "false")
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
@ -1077,7 +1082,7 @@ func TestReturnInt64(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
req.Header.Set(HTTPHeaderAllowInt64, "false")
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
@ -1167,7 +1172,7 @@ func TestUpsert(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(tt.mp, true)
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -1188,7 +1193,7 @@ func TestUpsert(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(mp, true)
|
|
|
|
|
bodyReader := bytes.NewReader([]byte(`{"collectionName": "` + DefaultCollectionName + `", "data": {}}`))
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorUpsertPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
@ -1271,7 +1276,7 @@ func TestSearch(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorSearchPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -1319,7 +1324,7 @@ func TestSearch(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
bodyReader := bytes.NewReader(data)
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, versional(VectorSearchPath), bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, tt.exceptCode, w.Code)
|
|
|
|
@ -1481,7 +1486,7 @@ func TestHttpRequestFormat(t *testing.T) {
|
|
|
|
|
testEngine := initHTTPServer(mocks.NewMockProxy(t), true)
|
|
|
|
|
bodyReader := bytes.NewReader(requestJsons[i])
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, path, bodyReader)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, util.DefaultRootPassword)
|
|
|
|
|
req.SetBasicAuth(util.UserRoot, getDefaultRootPassword())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
testEngine.ServeHTTP(w, req)
|
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
|
|
|