// TestEncodeSuccessfully tests that a stone was encoded successfully func TestEncodeSuccessfully(t *testing.T) { var meta = map[string]interface{}{ "id": util.NewID(), "type": "currency", "created_at": time.Now().Unix(), } sh, err := Create(meta, util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt")) assert.Nil(t, err) enc, _ := util.MapToJSON(sh.Signatures) expectedEncodeVal := crypto.ToBase64Raw([]byte(enc)) assert.Equal(t, sh.Encode(), expectedEncodeVal) }
// TestTokenToBlockWithMalformedJSONInPayload test that an error occurs if payload data is malformed func TestTokenToBlockWithMalformedJSONInPayload(t *testing.T) { malformedJSONPayload := crypto.ToBase64Raw([]byte(`{ "field": "value" `)) _, err := TokenToBlock("abcde."+malformedJSONPayload+".xyz", "meta") assert.NotNil(t, err) assert.Equal(t, err.Error(), "malformed meta block") }
// Returns a base64url encoded string of the signatures block func (self *Stone) Encode() string { var signaturesStr, _ = util.MapToJSON(self.Signatures) return crypto.ToBase64Raw([]byte(signaturesStr)) }