本文整理汇总了Golang中github.com/pomack/dsocial/go/api/apiutil.NewSigner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSigner函数的具体用法?Golang NewSigner怎么用?Golang NewSigner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSigner函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestUpdateUserAccountInvalidUserId
func TestUpdateUserAccountInvalidUserId(t *testing.T) {
ds, wm := initializeUpdateUserAccountDS()
gw, _ := ds.FindUserAccountByUsername("firstpresident")
accessKeys, _, _ := ds.RetrieveUserKeys(gw.Id, nil, 1)
accessKey := accessKeys[0]
otherUser, _ := ds.FindUserAccountByUsername("secondpresident")
anobj, _ := jsonhelper.Marshal(otherUser)
jsonobj := anobj.(jsonhelper.JSONObject)
jsonobj.Set("name", "Tom J")
jsonobj.Set("email", "[email protected]")
jsonobj.Set("address", "White House")
otherUser = new(dm.User)
otherUser.InitFromJSONObject(jsonobj)
jsonbuf, _ := json.Marshal(jsonobj)
req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/account/user/update/sdflsjflsjfslf", bytes.NewBuffer(jsonbuf))
req.Header.Set("Content-Type", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Accept-Encoding", "identity")
req.Header.Set("Accept-Language", "en-us")
req.Header.Set("Connection", "close")
apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
resp := webmachine.NewMockResponseWriter(req)
wm.ServeHTTP(resp, req)
if resp.StatusCode != http.StatusNotFound {
t.Error("Expected ", http.StatusNotFound, " status code but received ", resp.StatusCode)
}
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:28,代码来源:update_test.go
示例2: TestAuthSetPasswordAdmin
func TestAuthSetPasswordAdmin(t *testing.T) {
ds, wm := initializeAuthUserAccountDS()
user, _ := ds.FindUserAccountByUsername("firstpresident")
accessKeys, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000)
if len(accessKeys) != 1 {
t.Error("Expected to find 1 access key stored, but found", len(accessKeys))
}
accessKey := accessKeys[0]
jsonobj := jsonhelper.NewJSONObject()
jsonobj.Set("password", "hi ho hi ho")
jsonbuf, _ := json.Marshal(jsonobj)
req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/auth/set_password/", bytes.NewBuffer(jsonbuf))
req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Accept-Encoding", "identity")
req.Header.Set("Accept-Language", "en-us")
req.Header.Set("Connection", "close")
apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
reqbytes, _ := httputil.DumpRequest(req, true)
t.Log("Request is:\n", string(reqbytes), "\n\n")
resp := webmachine.NewMockResponseWriter(req)
wm.ServeHTTP(resp, req)
t.Log("Response is:\n", resp.String(), "\n\n")
if resp.StatusCode != http.StatusOK {
t.Error("Expected ", http.StatusOK, " status code but received ", resp.StatusCode)
}
if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
}
obj := jsonhelper.NewJSONObject()
err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
if err != nil {
t.Error("Unable to unmarshal setPassword response due to error:", err.Error())
}
if status := obj.GetAsString("status"); status != "success" {
t.Error("Expected successful operation, but had status:", status)
}
result := obj.GetAsObject("result")
if message := result.GetAsString("message"); message != "password changed" {
t.Error("Expected message == \"password changed\", but was \"", message, "\"")
}
user2 := result.GetAsObject("user")
uid := user2.GetAsString("id")
if uid != user.Id {
t.Error("Expected user id of", user.Id, ", but was", uid)
}
accessKeys2, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000)
if len(accessKeys2) != 1 {
t.Error("Expected to find one access key stored, but found", len(accessKeys))
}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:51,代码来源:set_password_test.go
示例3: TestViewUserAccountInvalidUserId
func TestViewUserAccountInvalidUserId(t *testing.T) {
ds, wm := initializeViewUserAccountDS()
gw, _ := ds.FindUserAccountByUsername("firstpresident")
accessKeys, _, _ := ds.RetrieveUserKeys(gw.Id, nil, 1)
accessKey := accessKeys[0]
req, _ := http.NewRequest(webmachine.GET, "http://localhost/api/v1/json/account/user/view/sdflsjflsjfslf", nil)
req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Accept-Encoding", "identity")
req.Header.Set("Accept-Language", "en-us")
req.Header.Set("Connection", "close")
apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
resp := webmachine.NewMockResponseWriter(req)
wm.ServeHTTP(resp, req)
if resp.StatusCode != http.StatusNotFound {
t.Error("Expected ", http.StatusNotFound, " status code but received ", resp.StatusCode)
}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:18,代码来源:view_test.go
示例4: TestViewUserAccountAsNonAdminForOtherUser
func TestViewUserAccountAsNonAdminForOtherUser(t *testing.T) {
ds, wm := initializeViewUserAccountDS()
ja, _ := ds.FindUserAccountByUsername("thirdpresident")
accessKeys, _, _ := ds.RetrieveUserKeys(ja.Id, nil, 1000)
if len(accessKeys) == 0 {
t.Error("Expected to find at least one access key stored.")
}
accessKey := accessKeys[0]
otherUser, _ := ds.FindUserAccountByUsername("secondpresident")
req, _ := http.NewRequest(webmachine.GET, "http://localhost/api/v1/json/account/user/view/"+otherUser.Id, nil)
req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Accept-Encoding", "identity")
req.Header.Set("Accept-Language", "en-us")
req.Header.Set("Connection", "close")
apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
resp := webmachine.NewMockResponseWriter(req)
wm.ServeHTTP(resp, req)
if resp.StatusCode != http.StatusForbidden {
t.Error("Expected ", http.StatusForbidden, " status code but received ", resp.StatusCode)
}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:22,代码来源:view_test.go
示例5: TestViewUserAccount
func TestViewUserAccount(t *testing.T) {
ds, wm := initializeViewUserAccountDS()
gw, _ := ds.FindUserAccountByUsername("firstpresident")
accessKeys, _, _ := ds.RetrieveUserKeys(gw.Id, nil, 1000)
if len(accessKeys) == 0 {
t.Error("Expected to find at least one access key stored.")
}
accessKey := accessKeys[0]
otherUser := gw
req, _ := http.NewRequest(webmachine.GET, "http://localhost/api/v1/json/account/user/view/"+otherUser.Id, nil)
req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
req.Header.Set("Accept-Charset", "utf-8")
req.Header.Set("Accept-Encoding", "identity")
req.Header.Set("Accept-Language", "en-us")
req.Header.Set("Connection", "close")
apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
resp := webmachine.NewMockResponseWriter(req)
wm.ServeHTTP(resp, req)
if resp.StatusCode != http.StatusOK {
t.Error("Expected ", http.StatusOK, " status code but received ", resp.StatusCode)
}
if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
}
user := new(dm.User)
obj := jsonhelper.NewJSONObject()
err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
user.InitFromJSONObject(obj.GetAsObject("result"))
if err != nil {
t.Error("Error while unmarshaling JSON: ", err.Error())
}
if obj.GetAsString("status") != "success" {
t.Error("Expected status = \"success\", but was \"", obj.GetAsString("status"), "\"")
}
if user.Name != otherUser.Name {
t.Error("Expected name = \"", otherUser.Name, "\", but was ", user.Name)
}
if user.Username != otherUser.Username {
t.Error("Expected username = \"", otherUser.Username, "\", but was ", user.Username)
}
if user.Email != otherUser.Email {
t.Error("Expected email = \"", otherUser.Email, "\", but was ", user.Email)
}
if user.PhoneNumber != otherUser.PhoneNumber {
t.Error("Expected phone_number = \"", otherUser.PhoneNumber, "\", but was ", user.PhoneNumber)
}
if user.Address != otherUser.Address {
t.Error("Expected address = \"", otherUser.Address, "\", but was ", user.Address)
}
if user.Role != otherUser.Role {
t.Error("Expected role = ", otherUser.Role, " but was ", user.Role)
}
if user.Id != otherUser.Id {
t.Error("Expected id to be ", otherUser.Id, ", but was ", user.Id)
}
if theuser, err := ds.RetrieveUserAccountById(otherUser.Id); err != nil || theuser == nil {
if theuser == nil {
t.Error("Unable to find User account by id ", otherUser.Id)
}
if err != nil {
t.Error("Error trying to find user account by id: ", err.Error())
}
}
if theuser, err := ds.FindUserAccountByUsername(otherUser.Username); err != nil || theuser == nil {
if theuser == nil {
t.Error("Unable to find User account by username ", otherUser.Username)
}
if err != nil {
t.Error("Error trying to find user account by username: ", err.Error())
}
}
if theusers, _, err := ds.FindUserAccountsByEmail(otherUser.Email, nil, 1000); err != nil || len(theusers) != 1 {
if len(theusers) != 1 {
t.Error("Found ", len(theusers), " User accounts by email for ", otherUser.Email, " rather than 1: ", theusers)
}
if err != nil {
t.Error("Error trying to find user accounts by email: ", err.Error())
}
}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:80,代码来源:view_test.go
注:本文中的github.com/pomack/dsocial/go/api/apiutil.NewSigner函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论