本文整理匯總了Golang中github.com/ellcrys/util.ReadFromFixtures函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadFromFixtures函數的具體用法?Golang ReadFromFixtures怎麽用?Golang ReadFromFixtures使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadFromFixtures函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestVerifyEmbeds
// TestVerifyEmbeds tests that an `embeds` block signed with a private key is
// successfully verified using the corresponding public key
func TestVerifyEmbeds(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_4.json"))
assert.Nil(t, err)
stone.Sign("embeds", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
err = stone.Verify("embeds", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.Nil(t, err)
}
示例2: TestVerifyOwnership
// TestVerifyOwnership tests that an ownership block signed with a private key is
// successfully verified using the corresponding public key
func TestVerifyOwnership(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_2.json"))
assert.Nil(t, err)
stone.Sign("ownership", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
err = stone.Verify("ownership", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.Nil(t, err)
}
示例3: TestCallVerifyWithUnknownBlockName
// TestCallVerifyWithUnknownBlockName tests that an error will occur when verifying an unknown block
func TestCallVerifyWithUnknownBlockName(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_2.json"))
assert.Nil(t, err)
err = stone.Verify("some_block", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.NotNil(t, err)
expectedMsg := "block unknown"
assert.Equal(t, expectedMsg, err.Error())
}
示例4: TestCallVerifyWithInvalidPublicKey
// TestCallVerifyWithInvalidPublicKey tests that an error will occur when verifying with an invalid public key
func TestCallVerifyWithInvalidPublicKey(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_2.json"))
assert.Nil(t, err)
stone.Sign("meta", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
err = stone.Verify("attributes", util.ReadFromFixtures("tests/fixtures/rsa_invalid_1.txt"))
assert.NotNil(t, err)
expectedMsg := `Public Key Error: unsupported key type "KEY"`
assert.Equal(t, expectedMsg, err.Error())
}
示例5: TestCannotSignUnknownBlock
// TestCannotSignUnknownBlock tests that an error will occur when attempting to sign an unknown block
func TestCannotSignUnknownBlock(t *testing.T) {
txt := util.ReadFromFixtures("tests/fixtures/stone_1.json")
stone, err := LoadJSON(txt)
assert.Nil(t, err)
_, err = stone.Sign("unknown_block", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.NotNil(t, err)
expectedMsg := "block unknown"
assert.Equal(t, err.Error(), expectedMsg)
}
示例6: TestCannotSignEmptyBlock
// TestCannotSignEmptyBlock tests that an error will occur when attempting to sign an empty block
func TestCannotSignEmptyBlock(t *testing.T) {
txt := util.ReadFromFixtures("tests/fixtures/stone_1.json")
stone, err := LoadJSON(txt)
assert.Nil(t, err)
_, err = stone.Sign("ownership", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.NotNil(t, err)
expectedMsg := "failed to sign empty block"
assert.Equal(t, err.Error(), expectedMsg)
}
示例7: TestDecodeWithSignedBlock
// TestDecodeWithSignedBlock tests that a encoded stone blocks will be decoded
// correctly as long as blocks where signed before the encoding process was run.
func TestDecodeWithSignedBlock(t *testing.T) {
sh, err := Load(util.ReadFromFixtures("tests/fixtures/stone_5.json"))
assert.Nil(t, err)
sh.Sign("meta", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
encStone := sh.Encode()
decStone, err := Decode(encStone)
assert.Nil(t, err)
assert.NotEqual(t, len(decStone.Meta), 0)
assert.Exactly(t, sh.Meta, decStone.Meta)
}
示例8: TestCorrectlySignMeta
// TestCorrectlySignMeta tests that a stone is correctly signed
func TestCorrectlySignMeta(t *testing.T) {
txt := util.ReadFromFixtures("tests/fixtures/stone_1.json")
stone, err := LoadJSON(txt)
assert.Nil(t, err)
expectedSignature := "eyJhbGciOiJSUzI1NiIsImp3ayI6eyJrdHkiOiJSU0EiLCJuIjoicTZHWW5qZ0tQYkxYSC1rZW5sbjZPZFZRcnl2SEMzVFV1ZS01dnh5QlRwaEhkUWc0djd1Mm9CczZYb1RRSVI2YS1UVlkwR2VFM3ZpakVaX1VwNlZDdG9YUEhWRk51VDBLSmJEaE1IajFVTmZJUnpTdUdOaWJ6bVAzX0NnanRvWWEwdXJyai1ubm5hWjBuYnBVdFRseDB5LW1jVUpnWGZSZDk0QzAtZ1JFUjBNIiwiZSI6IkFRQUIifX0.eyJjcmVhdGVkX2F0IjoxNDUzOTc1NTc1LCJpZCI6IjQ0MTc3ODE5MDZmYjBhODljMjk1OTU5YjBkZjAxNzgyZGJjNGRjOWYiLCJ0eXBlIjoiY3VycmVuY3kifQ.pEBlRBlIkmrMNJkBlvUWo5FK8N6-G83hirDNQLmYo6ojSkX0cXqak_mdHo7zUyLV0CxAvPuxb9fiYbz4S2tllIMpHm_RHQDDOXkl1ykiUrbcotrlfQmiOqvDzp91IL38m8Uy8-MBg-JB7K9nacCCLEph-BLn83AyyQeSVTQZGKo"
signature, err := stone.Sign("meta", util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.Nil(t, err)
assert.Equal(t, expectedSignature, signature)
assert.Equal(t, expectedSignature, stone.Signatures["meta"])
}
示例9: TestHasAttributesReturnsTrue
// TestHasAttributesReturnsTrue tests that a stone has attributes information
func TestHasAttributesReturnsTrue(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_1.json"))
assert.Nil(t, err)
var attrs = map[string]interface{}{
"ref_id": stone.Meta["id"],
"data": "some_value",
}
err = stone.AddAttributes(attrs, util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.Nil(t, err)
assert.Equal(t, stone.HasAttributes(), true)
}
示例10: TestHasOwnershipTrue
// TestHasOwnershipTrue tests that a stone has ownership information
func TestHasOwnershipTrue(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_1.json"))
assert.Nil(t, err)
var ownership = map[string]interface{}{
"ref_id": "4417781906fb0a89c295959b0df01782dbc4dc9f",
"type": "sole",
"sole": map[string]interface{}{
"address_id": "abcde",
},
}
err = stone.AddOwnership(ownership, util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.Nil(t, err)
assert.Equal(t, stone.HasOwnership(), true)
}
示例11: TestAddOwnershipWithUnsetMetaID
// TestAddOwnershipWithUnsetMetaID tests that an error will occur when attempting
// to set ownership to a stone with no meta id
func TestAddOwnershipWithUnsetMetaID(t *testing.T) {
var ownership = map[string]interface{}{}
sh := Empty()
err := sh.AddOwnership(ownership, util.ReadFromFixtures("tests/fixtures/rsa_priv_1.txt"))
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "meta.id is not set")
}
示例12: TestCallVerifyOnBlockWithNoSignature
// TestCallVerifyOnBlockWithNoSignature tests that an error will occur when verifying a block with no signature
// in the signatures block
func TestCallVerifyOnBlockWithNoSignature(t *testing.T) {
sh := Empty()
err := sh.Verify("attributes", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.NotNil(t, err)
expectedMsg := "`attributes` block has no signature"
assert.Equal(t, expectedMsg, err.Error())
}
示例13: TestCallVerifyWhenBlockSignatureIsMalformed
// TestCallVerifyWhenBlockSignatureIsMalformed tests that an error will occur when verifying a block that has
// an invalid JWS signature
func TestCallVerifyWhenBlockSignatureIsMalformed(t *testing.T) {
sh := Empty()
sh.Signatures["attributes"] = "abcdefaa9*"
err := sh.Verify("attributes", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.NotNil(t, err)
expectedMsg := "`attributes` block signature could not be verified"
assert.Equal(t, expectedMsg, err.Error())
}
示例14: TestCloneStone
// TestCloneStone
func TestCloneStone(t *testing.T) {
stone, err := LoadJSON(util.ReadFromFixtures("tests/fixtures/stone_2.json"))
assert.Nil(t, err)
clone := stone.Clone()
assert.Exactly(t, stone, clone)
stone.Signatures["meta"] = "blah_blah"
assert.NotEmpty(t, stone.Signatures["meta"], clone.Signatures["meta"])
}
示例15: TestCallVerifyWhenBlockSignatureInvalid
// TestCallVerifyWhenBlockSignatureInvalid tests that an error will occur when verifying a block
// that has an invalid signature
func TestCallVerifyWhenBlockSignatureInvalid(t *testing.T) {
sh := Empty()
tamperedSig := "enWGZSZIifX0.eyJjVycmVuY3kifQ.pEBlIL38m8Uy8-Ko"
sh.Signatures["attributes"] = tamperedSig
err := sh.Verify("attributes", util.ReadFromFixtures("tests/fixtures/rsa_pub_1.txt"))
assert.NotNil(t, err)
expectedMsg := "`attributes` block signature could not be verified"
assert.Equal(t, expectedMsg, err.Error())
}