mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-07-28 19:12:53 +00:00
This is a rather large change. It consists of the following changes: + Direct access to the keycache has been removed from the core package. This forces all interaction with the cache to go through the Cryptor, which is required for persistence. The Cryptor needs to know when the cache has changed, and the only way to do this effectively is to make the Cryptor responsible for managing the keycache. + A new persist package has been added. This provides a Store interface, for which two implementations are provided. The first is a null persister: this is used when no persistence is configured. The second is a file-backed persistence store. + The Cryptor now persists the cache every time it changes. Additionally, a number of missing returns in a function in the core package have been added.
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package persist
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cloudflare/redoctober/config"
|
|
"github.com/cloudflare/redoctober/passvault"
|
|
)
|
|
|
|
func TestNewNull(t *testing.T) {
|
|
cfg := &config.Delegations{
|
|
Persist: false,
|
|
Mechanism: FileMechanism,
|
|
Location: "testdata/store.bin",
|
|
Policy: "policy",
|
|
}
|
|
|
|
store, err := New(cfg)
|
|
if err != nil {
|
|
t.Fatalf("persist: failed to create a new store: %s", err)
|
|
}
|
|
|
|
if _, ok := store.(*Null); !ok {
|
|
t.Fatalf("persist: expected a Null store, but have %T", store)
|
|
}
|
|
|
|
if store.Blob() != nil {
|
|
t.Fatalf("persist: Null store should return an empty blob")
|
|
}
|
|
|
|
if store.Policy() != cfg.Policy {
|
|
t.Fatalf("persist: expected a consistent policy")
|
|
}
|
|
|
|
if err := store.Store([]byte("test data")); err != nil {
|
|
t.Fatalf("persist: Null.Store failed with %s", err)
|
|
}
|
|
|
|
if err := store.Load(); err != nil {
|
|
t.Fatalf("persist: Null.Load failed with %s", err)
|
|
}
|
|
|
|
status := store.Status()
|
|
if status.State != Disabled {
|
|
t.Fatalf("persist: Null store should never persist")
|
|
}
|
|
|
|
if len(status.Summary) != 0 {
|
|
t.Fatal("persist: Null summary should have zero entries")
|
|
}
|
|
|
|
err = store.Delegate(passvault.PasswordRecord{}, "name", "password", []string{}, []string{}, 1, "", "1h")
|
|
if err == nil {
|
|
t.Fatal("persist: expected delegation to fail")
|
|
}
|
|
|
|
if cache := store.Cache(); len(cache.UserKeys) != 0 {
|
|
t.Fatal("persist: Null Cache should return an empty cache")
|
|
}
|
|
}
|