MCPcopy Create free account
hub / github.com/git-bug/git-bug / TestStoreLoad

Function TestStoreLoad

entities/identity/key_test.go:26–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestStoreLoad(t *testing.T) {
27 repo := repository.NewMockRepoKeyring()
28
29 // public + private
30 k := GenerateKey()
31
32 // Store
33
34 dataJSON, err := json.Marshal(k)
35 require.NoError(t, err)
36
37 err = k.storePrivate(repo)
38 require.NoError(t, err)
39
40 // Load
41
42 var read Key
43 err = json.Unmarshal(dataJSON, &read)
44 require.NoError(t, err)
45
46 err = read.ensurePrivateKey(repo)
47 require.NoError(t, err)
48
49 require.Equal(t, k.public, read.public)
50
51 require.IsType(t, (*rsa.PrivateKey)(nil), k.private.PrivateKey)
52
53 // See https://github.com/golang/crypto/pull/175
54 rsaPriv := read.private.PrivateKey.(*rsa.PrivateKey)
55 rsaPriv.Primes[0], rsaPriv.Primes[1] = rsaPriv.Primes[1], rsaPriv.Primes[0]
56
57 require.True(t, k.private.PrivateKey.(*rsa.PrivateKey).Equal(read.private.PrivateKey))
58}

Callers

nothing calls this directly

Calls 4

ensurePrivateKeyMethod · 0.95
NewMockRepoKeyringFunction · 0.92
GenerateKeyFunction · 0.85
storePrivateMethod · 0.80

Tested by

no test coverage detected