本文整理汇总了Golang中github.com/snapcore/snapd/asserts.AssembleAndSignInTest函数的典型用法代码示例。如果您正苦于以下问题:Golang AssembleAndSignInTest函数的具体用法?Golang AssembleAndSignInTest怎么用?Golang AssembleAndSignInTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssembleAndSignInTest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAccountKeyCheckSameNameAndNewRevision
func (aks *accountKeySuite) TestAccountKeyCheckSameNameAndNewRevision(c *C) {
trustedKey := testPrivKey0
headers := map[string]interface{}{
"authority-id": "canonical",
"account-id": "acc-id1",
"name": "default",
"public-key-sha3-384": aks.keyID,
"since": aks.since.Format(time.RFC3339),
"until": aks.until.Format(time.RFC3339),
}
accKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, []byte(aks.pubKeyBody), trustedKey)
c.Assert(err, IsNil)
db := aks.openDB(c)
aks.prereqAccount(c, db)
err = db.Add(accKey)
c.Assert(err, IsNil)
headers["revision"] = "1"
newAccKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, []byte(aks.pubKeyBody), trustedKey)
c.Assert(err, IsNil)
err = db.Check(newAccKey)
c.Assert(err, IsNil)
}
示例2: TestSelfRef
func (as *assertsSuite) TestSelfRef(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
a1, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Assert(err, IsNil)
c.Check(a1.Ref(), DeepEquals, &asserts.Ref{
Type: asserts.TestOnlyType,
PrimaryKey: []string{"0"},
})
headers = map[string]interface{}{
"authority-id": "auth-id1",
"pk1": "a",
"pk2": "b",
}
a2, err := asserts.AssembleAndSignInTest(asserts.TestOnly2Type, headers, nil, testPrivKey1)
c.Assert(err, IsNil)
c.Check(a2.Ref(), DeepEquals, &asserts.Ref{
Type: asserts.TestOnly2Type,
PrimaryKey: []string{"a", "b"},
})
}
示例3: TestAccountKeyCheckNameClash
func (aks *accountKeySuite) TestAccountKeyCheckNameClash(c *C) {
trustedKey := testPrivKey0
headers := map[string]interface{}{
"authority-id": "canonical",
"account-id": "acc-id1",
"name": "default",
"public-key-sha3-384": aks.keyID,
"since": aks.since.Format(time.RFC3339),
"until": aks.until.Format(time.RFC3339),
}
accKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, []byte(aks.pubKeyBody), trustedKey)
c.Assert(err, IsNil)
db := aks.openDB(c)
aks.prereqAccount(c, db)
err = db.Add(accKey)
c.Assert(err, IsNil)
newPrivKey, _ := assertstest.GenerateKey(752)
err = db.ImportKey(newPrivKey)
c.Assert(err, IsNil)
newPubKey, err := db.PublicKey(newPrivKey.PublicKey().ID())
c.Assert(err, IsNil)
newPubKeyEncoded, err := asserts.EncodePublicKey(newPubKey)
headers["public-key-sha3-384"] = newPubKey.ID()
headers["revision"] = "1"
newAccKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, newPubKeyEncoded, trustedKey)
c.Assert(err, IsNil)
err = db.Check(newAccKey)
c.Assert(err, ErrorMatches, fmt.Sprintf(`account-key assertion for "acc-id1" with ID %q has the same name "default" as existing ID %q`, newPubKey.ID(), aks.keyID))
}
示例4: TestAccountKeyCheckSameAccountAndDifferentName
func (aks *accountKeySuite) TestAccountKeyCheckSameAccountAndDifferentName(c *C) {
trustedKey := testPrivKey0
headers := map[string]interface{}{
"authority-id": "canonical",
"account-id": "acc-id1",
"name": "default",
"public-key-sha3-384": aks.keyID,
"since": aks.since.Format(time.RFC3339),
"until": aks.until.Format(time.RFC3339),
}
accKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, []byte(aks.pubKeyBody), trustedKey)
c.Assert(err, IsNil)
db := aks.openDB(c)
aks.prereqAccount(c, db)
err = db.Add(accKey)
c.Assert(err, IsNil)
newPrivKey, _ := assertstest.GenerateKey(752)
err = db.ImportKey(newPrivKey)
c.Assert(err, IsNil)
newPubKey, err := db.PublicKey(newPrivKey.PublicKey().ID())
c.Assert(err, IsNil)
newPubKeyEncoded, err := asserts.EncodePublicKey(newPubKey)
headers["name"] = "another"
headers["public-key-sha3-384"] = newPubKey.ID()
newAccKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, newPubKeyEncoded, trustedKey)
c.Assert(err, IsNil)
err = db.Check(newAccKey)
c.Assert(err, IsNil)
}
示例5: TestSignFormatSanitySupportMultilineHeaderValues
func (as *assertsSuite) TestSignFormatSanitySupportMultilineHeaderValues(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
multilineVals := []string{
"a\n",
"\na",
"a\n\b\nc",
"a\n\b\nc\n",
"\na\n",
"\n\na\n\nb\n\nc",
}
for _, multilineVal := range multilineVals {
headers["multiline"] = multilineVal
if len(multilineVal)%2 == 1 {
headers["odd"] = "true"
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Assert(err, IsNil)
decoded, err := asserts.Decode(asserts.Encode(a))
c.Assert(err, IsNil)
c.Check(decoded.Header("multiline"), Equals, multilineVal)
}
}
示例6: TestAccountKeyAddAndFind
func (aks *accountKeySuite) TestAccountKeyAddAndFind(c *C) {
trustedKey := testPrivKey0
headers := map[string]interface{}{
"authority-id": "canonical",
"account-id": "acc-id1",
"name": "default",
"public-key-sha3-384": aks.keyID,
"since": aks.since.Format(time.RFC3339),
"until": aks.until.Format(time.RFC3339),
}
accKey, err := asserts.AssembleAndSignInTest(asserts.AccountKeyType, headers, []byte(aks.pubKeyBody), trustedKey)
c.Assert(err, IsNil)
db := aks.openDB(c)
aks.prereqAccount(c, db)
err = db.Add(accKey)
c.Assert(err, IsNil)
found, err := db.Find(asserts.AccountKeyType, map[string]string{
"account-id": "acc-id1",
"public-key-sha3-384": aks.keyID,
})
c.Assert(err, IsNil)
c.Assert(found, NotNil)
c.Check(found.Body(), DeepEquals, []byte(aks.pubKeyBody))
}
示例7: TestCheckUnsupportedFormat
func (chks *checkSuite) TestCheckUnsupportedFormat(c *C) {
trustedKey := testPrivKey0
cfg := &asserts.DatabaseConfig{
Backstore: chks.bs,
Trusted: []asserts.Assertion{asserts.BootstrapAccountKeyForTest("canonical", trustedKey.PublicKey())},
}
db, err := asserts.OpenDatabase(cfg)
c.Assert(err, IsNil)
var a asserts.Assertion
(func() {
restore := asserts.MockMaxSupportedFormat(asserts.TestOnlyType, 77)
defer restore()
var err error
headers := map[string]interface{}{
"authority-id": "canonical",
"primary-key": "0",
"format": "77",
}
a, err = asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, trustedKey)
c.Assert(err, IsNil)
})()
err = db.Check(a)
c.Assert(err, FitsTypeOf, &asserts.UnsupportedFormatError{})
c.Check(err, ErrorMatches, `proposed "test-only" assertion has format 77 but 1 is latest supported`)
}
示例8: TestOpenDatabaseTrustedAccount
func (opens *openSuite) TestOpenDatabaseTrustedAccount(c *C) {
headers := map[string]interface{}{
"authority-id": "canonical",
"account-id": "trusted",
"display-name": "Trusted",
"validation": "certified",
"timestamp": "2015-01-01T14:00:00Z",
}
acct, err := asserts.AssembleAndSignInTest(asserts.AccountType, headers, nil, testPrivKey0)
c.Assert(err, IsNil)
cfg := &asserts.DatabaseConfig{
Backstore: asserts.NewMemoryBackstore(),
Trusted: []asserts.Assertion{acct},
}
db, err := asserts.OpenDatabase(cfg)
c.Assert(err, IsNil)
a, err := db.Find(asserts.AccountType, map[string]string{
"account-id": "trusted",
})
c.Assert(err, IsNil)
acct1 := a.(*asserts.Account)
c.Check(acct1.AccountID(), Equals, "trusted")
c.Check(acct1.DisplayName(), Equals, "Trusted")
c.Check(db.IsTrustedAccount("trusted"), Equals, true)
// empty account id (invalid) is not trusted
c.Check(db.IsTrustedAccount(""), Equals, false)
}
示例9: TestSignBodyIsUTF8Text
func (as *assertsSuite) TestSignBodyIsUTF8Text(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
_, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, []byte{'\xff'}, testPrivKey1)
c.Assert(err, ErrorMatches, "assertion body is not utf8")
}
示例10: TestSignFormatSanityEmptyBody
func (as *assertsSuite) TestSignFormatSanityEmptyBody(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Assert(err, IsNil)
_, err = asserts.Decode(asserts.Encode(a))
c.Check(err, IsNil)
}
示例11: TestSignKeyID
func (as *assertsSuite) TestSignKeyID(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Assert(err, IsNil)
keyID := a.SignKeyID()
c.Check(keyID, Equals, testPrivKey1.PublicKey().ID())
}
示例12: SetUpTest
func (chks *checkSuite) SetUpTest(c *C) {
var err error
topDir := filepath.Join(c.MkDir(), "asserts-db")
chks.bs, err = asserts.OpenFSBackstore(topDir)
c.Assert(err, IsNil)
headers := map[string]interface{}{
"authority-id": "canonical",
"primary-key": "0",
}
chks.a, err = asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey0)
c.Assert(err, IsNil)
}
示例13: TestOpenDatabaseTrustedWrongType
func (opens *openSuite) TestOpenDatabaseTrustedWrongType(c *C) {
headers := map[string]interface{}{
"authority-id": "canonical",
"primary-key": "0",
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey0)
cfg := &asserts.DatabaseConfig{
Trusted: []asserts.Assertion{a},
}
_, err = asserts.OpenDatabase(cfg)
c.Assert(err, ErrorMatches, "cannot load trusted assertions that are not account-key or account: test-only")
}
示例14: TestSignFormatSanityNonEmptyBody
func (as *assertsSuite) TestSignFormatSanityNonEmptyBody(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
}
body := []byte("THE-BODY")
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, body, testPrivKey1)
c.Assert(err, IsNil)
c.Check(a.Body(), DeepEquals, body)
decoded, err := asserts.Decode(asserts.Encode(a))
c.Assert(err, IsNil)
c.Check(decoded.Body(), DeepEquals, body)
}
示例15: prereqAccount
func (aks *accountKeySuite) prereqAccount(c *C, db *asserts.Database) {
trustedKey := testPrivKey0
headers := map[string]interface{}{
"authority-id": "canonical",
"display-name": "Acct1",
"account-id": "acc-id1",
"username": "acc-id1",
"validation": "unproven",
"timestamp": aks.since.Format(time.RFC3339),
}
acct1, err := asserts.AssembleAndSignInTest(asserts.AccountType, headers, nil, trustedKey)
c.Assert(err, IsNil)
// prereq
db.Add(acct1)
}