mirror of
https://github.com/balzack/databag.git
synced 2025-04-22 01:25:17 +00:00
implementing connect use case test
This commit is contained in:
parent
06958c80c5
commit
59ae141d31
40
net/server/internal/api_getProfileMessage.go
Normal file
40
net/server/internal/api_getProfileMessage.go
Normal file
@ -0,0 +1,40 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetProfileMessage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, res := BearerAppToken(r, true);
|
||||
if res != nil {
|
||||
ErrResponse(w, http.StatusUnauthorized, res)
|
||||
return
|
||||
}
|
||||
if account.Disabled {
|
||||
ErrResponse(w, http.StatusGone, res)
|
||||
return
|
||||
}
|
||||
detail := account.AccountDetail
|
||||
|
||||
// generate identity DataMessage
|
||||
identity := Identity{
|
||||
Revision: account.ProfileRevision,
|
||||
Handle: account.Username,
|
||||
Name: detail.Name,
|
||||
Description: detail.Description,
|
||||
Location: detail.Location,
|
||||
Image: detail.Image,
|
||||
Version: APP_VERSION,
|
||||
Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/",
|
||||
}
|
||||
msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||
APP_SIGNPKCS1V15, account.Guid, APP_MSGIDENTITY, &identity)
|
||||
if res != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, msg)
|
||||
}
|
||||
|
@ -18,11 +18,6 @@ func GetProfileImage(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetProfileMessage(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func SetProfileImage(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -55,7 +55,7 @@ func TestConnectContact(t *testing.T) {
|
||||
|
||||
// acquire new token for attaching app
|
||||
r, w, _ = NewRequest("POST", "/account/apps", nil)
|
||||
SetBasicAuth(r, "attachapp:pass");
|
||||
SetBasicAuth(r, "connectb:pass");
|
||||
AddAccountApp(w, r);
|
||||
assert.NoError(t, ReadResponse(w, &token))
|
||||
|
||||
@ -66,9 +66,22 @@ func TestConnectContact(t *testing.T) {
|
||||
var bToken string
|
||||
assert.NoError(t, ReadResponse(w, &bToken))
|
||||
|
||||
// get B identity message
|
||||
r, w, _ = NewRequest("GET", "/profile/message", nil)
|
||||
SetBearerAuth(r, bToken)
|
||||
GetProfileMessage(w, r)
|
||||
var msg DataMessage
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
var identity Identity
|
||||
guid, messageType, ts, err := ReadDataMessage(&msg, &identity)
|
||||
|
||||
// get B profile message
|
||||
PrintMsg(msg)
|
||||
PrintMsg(guid)
|
||||
PrintMsg(messageType)
|
||||
PrintMsg(ts)
|
||||
PrintMsg(err)
|
||||
PrintMsg(identity)
|
||||
|
||||
// set B card in A
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user