本文整理汇总了Golang中github.com/snapcore/snapd/asserts.AssembleAndSignInTest函数的典型用法代码示例。如果您正苦于以下问题:Golang AssembleAndSignInTest函数的具体用法?Golang AssembleAndSignInTest怎么用?Golang AssembleAndSignInTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssembleAndSignInTest函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:pedronis,项目名称:snappy,代码行数:27,代码来源:account_key_test.go
示例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"},
})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:26,代码来源:asserts_test.go
示例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))
}
开发者ID:niemeyer,项目名称:snapd,代码行数:35,代码来源:account_key_test.go
示例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)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:35,代码来源:account_key_test.go
示例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)
}
}
开发者ID:niemeyer,项目名称:snapd,代码行数:30,代码来源:asserts_test.go
示例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))
}
开发者ID:pedronis,项目名称:snappy,代码行数:29,代码来源:account_key_test.go
示例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`)
}
开发者ID:pedronis,项目名称:snappy,代码行数:29,代码来源:database_test.go
示例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)
}
开发者ID:pedronis,项目名称:snappy,代码行数:32,代码来源:database_test.go
示例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")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:8,代码来源:asserts_test.go
示例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)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:11,代码来源:asserts_test.go
示例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())
}
开发者ID:niemeyer,项目名称:snapd,代码行数:11,代码来源:asserts_test.go
示例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)
}
开发者ID:pedronis,项目名称:snappy,代码行数:14,代码来源:database_test.go
示例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")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:database_test.go
示例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)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:asserts_test.go
示例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)
}
开发者ID:pedronis,项目名称:snappy,代码行数:17,代码来源:account_key_test.go
示例16: TestWithAuthority
func (as *assertsSuite) TestWithAuthority(c *C) {
withAuthority := []string{
"account",
"account-key",
"snap-declaration",
"snap-build",
"snap-revision",
"model",
"serial",
"system-user",
"validation",
}
c.Check(withAuthority, HasLen, asserts.NumAssertionType-4) // excluding device-session-request, serial-request, serial-proof, account-key-request
for _, name := range withAuthority {
typ := asserts.Type(name)
_, err := asserts.AssembleAndSignInTest(typ, nil, nil, testPrivKey1)
c.Check(err, ErrorMatches, `"authority-id" header is mandatory`)
}
}
开发者ID:clobrano,项目名称:snappy,代码行数:19,代码来源:asserts_test.go
示例17: TestAddUnsupportedFormat
func (safs *signAddFindSuite) TestAddUnsupportedFormat(c *C) {
const unsupported = "type: test-only\n" +
"format: 77\n" +
"authority-id: canonical\n" +
"primary-key: a\n" +
"payload: unsupported\n" +
"sign-key-sha3-384: Jv8_JiHiIzJVcO9M55pPdqSDWUvuhfDIBJUS-3VW7F_idjix7Ffn5qMxB21ZQuij" +
"\n\n" +
"AXNpZw=="
headers := map[string]interface{}{
"authority-id": "canonical",
"primary-key": "a",
"format": "77",
"payload": "unsupported",
}
aUnsupp, err := asserts.Decode([]byte(unsupported))
c.Assert(err, IsNil)
c.Assert(aUnsupp.SupportedFormat(), Equals, false)
err = safs.db.Add(aUnsupp)
c.Assert(err, FitsTypeOf, &asserts.UnsupportedFormatError{})
c.Check(err.(*asserts.UnsupportedFormatError).Update, Equals, false)
c.Check(err, ErrorMatches, `proposed "test-only" assertion has format 77 but 1 is latest supported`)
c.Check(asserts.IsUnaccceptedUpdate(err), Equals, false)
headers = map[string]interface{}{
"authority-id": "canonical",
"primary-key": "a",
"format": "1",
"payload": "supported",
}
aSupp, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey0)
c.Assert(err, IsNil)
err = safs.db.Add(aSupp)
c.Assert(err, IsNil)
err = safs.db.Add(aUnsupp)
c.Assert(err, FitsTypeOf, &asserts.UnsupportedFormatError{})
c.Check(err.(*asserts.UnsupportedFormatError).Update, Equals, true)
c.Check(err, ErrorMatches, `proposed "test-only" assertion has format 77 but 1 is latest supported \(current not updated\)`)
c.Check(asserts.IsUnaccceptedUpdate(err), Equals, true)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:43,代码来源:database_test.go
示例18: TestAccountKeyCheckNoAccount
func (aks *accountKeySuite) TestAccountKeyCheckNoAccount(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)
err = db.Check(accKey)
c.Assert(err, ErrorMatches, `account-key assertion for "acc-id1" does not have a matching account assertion`)
}
开发者ID:pedronis,项目名称:snappy,代码行数:19,代码来源:account_key_test.go
示例19: TestSignFormatAndRevision
func (as *assertsSuite) TestSignFormatAndRevision(c *C) {
headers := map[string]interface{}{
"authority-id": "auth-id1",
"primary-key": "0",
"format": "1",
"revision": "11",
}
a, err := asserts.AssembleAndSignInTest(asserts.TestOnlyType, headers, nil, testPrivKey1)
c.Check(a.Revision(), Equals, 11)
c.Check(a.Format(), Equals, 1)
c.Check(a.SupportedFormat(), Equals, true)
a1, err := asserts.Decode(asserts.Encode(a))
c.Assert(err, IsNil)
c.Check(a1.Revision(), Equals, 11)
c.Check(a1.Format(), Equals, 1)
c.Check(a1.SupportedFormat(), Equals, true)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:21,代码来源:asserts_test.go
注:本文中的github.com/snapcore/snapd/asserts.AssembleAndSignInTest函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论