本文整理匯總了Golang中github.com/docker/swarmkit/api.MaybeEncryptedRecord類的典型用法代碼示例。如果您正苦於以下問題:Golang MaybeEncryptedRecord類的具體用法?Golang MaybeEncryptedRecord怎麽用?Golang MaybeEncryptedRecord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MaybeEncryptedRecord類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestReadAllWrappedNoEncryption
// WAL can read entries are not wrapped, but not encrypted
func TestReadAllWrappedNoEncryption(t *testing.T) {
metadata, entries, snapshot := makeWALData(1, 1)
wrappedEntries := make([]raftpb.Entry, len(entries))
for i, entry := range entries {
r := api.MaybeEncryptedRecord{Data: entry.Data}
data, err := r.Marshal()
require.NoError(t, err)
entry.Data = data
wrappedEntries[i] = entry
}
tempdir := createWithWAL(t, OriginalWAL, metadata, snapshot, wrappedEntries)
defer os.RemoveAll(tempdir)
c := NewWALFactory(encryption.NoopCrypter, encryption.NoopCrypter)
wrapped, err := c.Open(tempdir, snapshot)
require.NoError(t, err)
defer wrapped.Close()
metaW, _, entsW, err := wrapped.ReadAll()
require.NoError(t, err)
require.NoError(t, wrapped.Close())
require.Equal(t, metadata, metaW)
require.Equal(t, entries, entsW)
}
示例2: TestSnapshotterLoadDecryptingFail
// If decrypting a snapshot fails, the error is propagated
func TestSnapshotterLoadDecryptingFail(t *testing.T) {
tempdir, err := ioutil.TempDir("", "snapwrap")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
crypter := &meowCrypter{}
ogSnap := OriginalSnap.New(tempdir)
r := api.MaybeEncryptedRecord{
Data: fakeSnapshotData.Data,
Algorithm: crypter.Algorithm(),
}
data, err := r.Marshal()
require.NoError(t, err)
emptyEncryptionFakeData := fakeSnapshotData
emptyEncryptionFakeData.Data = data
require.NoError(t, ogSnap.SaveSnap(emptyEncryptionFakeData))
c := NewSnapFactory(encryption.NoopCrypter, crypter)
wrapped := c.New(tempdir)
_, err = wrapped.Load()
require.Error(t, err)
require.Contains(t, err.Error(), "not meowcoded")
}
示例3: TestSnapshotterSavesSnapshotWithEncryption
// The snapshot data (but not metadata or anything else) is encryptd before being
// passed to the wrapped Snapshotter.
func TestSnapshotterSavesSnapshotWithEncryption(t *testing.T) {
tempdir, err := ioutil.TempDir("", "snapwrap")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
c := NewSnapFactory(meowCrypter{}, encryption.NoopCrypter)
wrapped := c.New(tempdir)
require.NoError(t, wrapped.SaveSnap(fakeSnapshotData))
ogSnap := OriginalSnap.New(tempdir)
readSnap, err := ogSnap.Load()
require.NoError(t, err)
r := api.MaybeEncryptedRecord{}
require.NoError(t, r.Unmarshal(readSnap.Data))
require.NotEqual(t, fakeSnapshotData.Data, r.Data)
require.Equal(t, fakeSnapshotData.Metadata, readSnap.Metadata)
}
示例4: TestReadAllNoSupportedDecrypter
// When reading WAL, if the decrypter can't read the encryption type, errors
func TestReadAllNoSupportedDecrypter(t *testing.T) {
metadata, entries, snapshot := makeWALData(1, 1)
for i, entry := range entries {
r := api.MaybeEncryptedRecord{Data: entry.Data, Algorithm: api.MaybeEncryptedRecord_Algorithm(-3)}
data, err := r.Marshal()
require.NoError(t, err)
entries[i].Data = data
}
tempdir := createWithWAL(t, OriginalWAL, metadata, snapshot, entries)
defer os.RemoveAll(tempdir)
c := NewWALFactory(encryption.NoopCrypter, encryption.NoopCrypter)
wrapped, err := c.Open(tempdir, snapshot)
require.NoError(t, err)
defer wrapped.Close()
_, _, _, err = wrapped.ReadAll()
require.Error(t, err)
defer wrapped.Close()
}
示例5: TestSave
// The entry data and metadata are encryptd with the given encrypter, and a regular
// WAL will see them as such.
func TestSave(t *testing.T) {
metadata, entries, snapshot := makeWALData(1, 1)
crypter := &meowCrypter{}
c := NewWALFactory(crypter, encryption.NoopCrypter)
tempdir := createWithWAL(t, c, metadata, snapshot, entries)
defer os.RemoveAll(tempdir)
ogWAL, err := OriginalWAL.Open(tempdir, snapshot)
require.NoError(t, err)
defer ogWAL.Close()
meta, state, ents, err := ogWAL.ReadAll()
require.NoError(t, err)
require.Equal(t, metadata, meta)
require.Equal(t, state, state)
for _, ent := range ents {
var encrypted api.MaybeEncryptedRecord
require.NoError(t, encrypted.Unmarshal(ent.Data))
require.Equal(t, crypter.Algorithm(), encrypted.Algorithm)
require.True(t, bytes.HasSuffix(encrypted.Data, []byte("🐱")))
}
}
示例6: TestReadAllEntryIncorrectlyEncrypted
// When reading WAL, if a decrypter is available for the encryption type but any
// entry is incorrectly encryptd, an error is returned
func TestReadAllEntryIncorrectlyEncrypted(t *testing.T) {
crypter := &meowCrypter{}
metadata, entries, snapshot := makeWALData(1, 1)
// metadata is correctly encryptd, but entries are not meow-encryptd
for i, entry := range entries {
r := api.MaybeEncryptedRecord{Data: entry.Data, Algorithm: crypter.Algorithm()}
data, err := r.Marshal()
require.NoError(t, err)
entries[i].Data = data
}
tempdir := createWithWAL(t, OriginalWAL, metadata, snapshot, entries)
defer os.RemoveAll(tempdir)
c := NewWALFactory(encryption.NoopCrypter, crypter)
wrapped, err := c.Open(tempdir, snapshot)
require.NoError(t, err)
_, _, _, err = wrapped.ReadAll()
require.Error(t, err)
require.Contains(t, err.Error(), "not meowcoded")
require.NoError(t, wrapped.Close())
}
示例7: TestSnapshotterLoadNotEncryptedSnapshot
// Snapshotter can read snapshots that are wrapped, but not encrypted
func TestSnapshotterLoadNotEncryptedSnapshot(t *testing.T) {
tempdir, err := ioutil.TempDir("", "snapwrap")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
ogSnap := OriginalSnap.New(tempdir)
r := api.MaybeEncryptedRecord{
Data: fakeSnapshotData.Data,
}
data, err := r.Marshal()
require.NoError(t, err)
emptyEncryptionFakeData := fakeSnapshotData
emptyEncryptionFakeData.Data = data
require.NoError(t, ogSnap.SaveSnap(emptyEncryptionFakeData))
c := NewSnapFactory(encryption.NoopCrypter, encryption.NoopCrypter)
wrapped := c.New(tempdir)
readSnap, err := wrapped.Load()
require.NoError(t, err)
require.Equal(t, fakeSnapshotData, *readSnap)
}