MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestInvalidKeystoreFileRecover

Function TestInvalidKeystoreFileRecover

crypto/kms/pubkeystore_test.go:138–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestInvalidKeystoreFileRecover(t *testing.T) {
139 Convey("invalid file recover", t, func() {
140 ClosePublicKeyStore()
141 utils.RemoveAll(dbFile + "*")
142 defer utils.RemoveAll(dbFile + "*")
143 var err error
144 err = ioutil.WriteFile(dbFile, []byte("UNKNOWN_DATA_MUST_NOT_BE_A_SQLITE_DATABASE"), 0600)
145 So(err, ShouldBeNil)
146 st, err := os.Stat(dbFile)
147 So(err, ShouldBeNil)
148 So(st.IsDir(), ShouldBeFalse)
149 err = InitPublicKeyStore(dbFile, nil)
150 So(err, ShouldBeNil)
151 // backup should exists
152 st, err = os.Stat(dbFile + ".bak")
153 So(err, ShouldBeNil)
154 So(st.IsDir(), ShouldBeFalse)
155 })
156
157 Convey("backup keystore file should not be overwritten if exists", t, func() {
158 ClosePublicKeyStore()
159 backupFile := dbFile + ".bak"
160 utils.RemoveAll(dbFile + "*")
161 defer utils.RemoveAll(dbFile + "*")
162
163 var err error
164 err = ioutil.WriteFile(dbFile, []byte("backup_1"), 0600)
165 So(err, ShouldBeNil)
166 err = ioutil.WriteFile(backupFile, []byte("backup_2"), 0600)
167 So(err, ShouldBeNil)
168 st, err := os.Stat(dbFile)
169 So(err, ShouldBeNil)
170 So(st.IsDir(), ShouldBeFalse)
171 st, err = os.Stat(backupFile)
172 So(err, ShouldBeNil)
173 So(st.IsDir(), ShouldBeFalse)
174 err = InitPublicKeyStore(dbFile, nil)
175 So(err, ShouldBeNil)
176 // backup should not be overwritten
177 backupData, err := ioutil.ReadFile(backupFile)
178 So(err, ShouldBeNil)
179 So(backupData, ShouldResemble, []byte("backup_2"))
180 })
181
182 Convey("sqlite keystore should not be truncated", t, func() {
183 ClosePublicKeyStore()
184 utils.RemoveAll(dbFile + "*")
185 defer utils.RemoveAll(dbFile + "*")
186
187 _, pubKey1, _ := asymmetric.GenSecp256k1KeyPair()
188 node1 := &proto.Node{
189 ID: proto.NodeID("1111"),
190 Addr: "",
191 PublicKey: pubKey1,
192 Nonce: cpuminer.Uint256{},
193 }
194
195 var err error

Callers

nothing calls this directly

Calls 8

RemoveAllFunction · 0.92
GenSecp256k1KeyPairFunction · 0.92
NodeIDTypeAlias · 0.92
ClosePublicKeyStoreFunction · 0.85
InitPublicKeyStoreFunction · 0.85
setNodeFunction · 0.85
StatMethod · 0.80
GetNodeInfoFunction · 0.70

Tested by

no test coverage detected