Esempio n. 1
0
func TestBadMailbox(t *testing.T) {
	key := mailbox.AccessKey{FullAccess: true}
	key.Create()
	req := api.GetMessageRequest{Mailbox: "111"}
	req.Sign(key.Name, key.Secret)
	var resp api.GetMessageResponse
	code := doRequest(t, req, &resp, "get")
	if code != 400 {
		t.Fatal("Should of responded with 400 but it responded with", code)
	}
}
Esempio n. 2
0
// Get retrieves a message from the server via a JSON api.
func (client *Client) Get() (*api.GetMessageResponse, error) {
	request := api.GetMessageRequest{Mailbox: client.Mailbox}
	request.Sign(client.AccessKeyName, client.AccessKey)
	var response api.GetMessageResponse
	err := client.request("get", request, &response)
	if err != nil {
		return nil, err
	}
	if !response.IsEmpty() {
		if !response.Validate(client.AccessKey) {
			return nil, errors.New("Could not validate the server's signature")
		}
	}
	return &response, nil
}
Esempio n. 3
0
func TestGet(t *testing.T) {
	dep, err := generateDeployment()
	if err != nil {
		t.Fatal(err)
	}
	req := api.GetMessageRequest{Mailbox: dep.Mailbox.Id}
	req.Sign(dep.AccessKey.Name, dep.AccessKey.Secret)
	var resp api.GetMessageResponse
	doRequest(t, req, &resp, "get")
	if resp.Body != dep.Message.Body {
		t.Fatalf("Message body TEST!=%s", dep.Message.Body)
	}
	if resp.ReceiveCount != 1 {
		t.Fatal("Message receiveCount is not 1")
	}

	doRequest(t, req, &resp, "get")
	if resp.ReceiveCount != 2 {
		t.Fatal("Message receiveCount did not increase to 2 on second call")
	}
}