MCPcopy Create free account
hub / github.com/dwin/goSecretBoxPassword / TestUpdateMaster

Function TestUpdateMaster

password_test.go:172–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

170
171}
172func TestUpdateMaster(t *testing.T) {
173 output, err := Hash("password1234", "masterpassphrase", 0, ScryptParams{N: 32768, R: 16, P: 1}, DefaultParams)
174 if err != nil {
175 t.Log(err)
176 t.FailNow()
177 }
178 fmt.Println("Output: " + output)
179 fmt.Printf("Length: %v\n", len(output))
180
181 err = Verify("password1234", "masterpassphrase", output)
182 if err != nil {
183 t.Log(err)
184 t.FailNow()
185 }
186 // Update then re-verify
187 updated, err := UpdateMaster("masterpassphrase2", "masterpassphrase", 1, output, DefaultParams)
188 if err != nil {
189 t.Log(err)
190 t.FailNow()
191 }
192 fmt.Println("Updated Output: " + updated)
193 fmt.Printf("Updated Length: %v\n", len(updated))
194 err = Verify("password1234", "masterpassphrase2", updated)
195 if err != nil {
196 t.Log(err)
197 t.FailNow()
198 }
199
200 // Test Bad Format Fail
201 _, err = UpdateMaster("masterpassphrase2", "masterpassphrase", 1, "secBoxv1$l8W69jygGur7sa0669mAJnIuYgjsbkx4wd+RdDzwIn2Z49FJurWkJDx2NA8g+ED9Nn6vGCLNFoHXSDIDeDBvJXouxs5zyX6mVozceVAVO7IadrL4+KKohV3MzoVlgodUYeNToOVB/5A=$4LZVjQ8P9pA=$32768$16$1$16384$8$1", DefaultParams)
202 if err != ErrCiphertextFormat {
203 t.Log("Expected Ciphertext format failure")
204 t.FailNow()
205 }
206
207 // Test Bad Params Fail
208 _, err = UpdateMaster("masterpassphrase2", "masterpassphrase", 1, "secBoxv1$0$l8W69jygGur7sa0669mAJnIuYgjsbkx4wd+RdDzwIn2Z49FJurWkJDx2NA8g+ED9Nn6vGCLNFoHXSDIDeDBvJXouxs5zyX6mVozceVAVO7IadrL4+KKohV3MzoVlgodUYeNToOVB/5A=$4LZVjQ8P9pA=$32768$16$1$16384$8$1", ScryptParams{N: 2048, R: 8, P: 1})
209 if err != ErrScryptParamN {
210 t.Log(err)
211 t.Log("Expected Scrypt N param failure")
212 t.FailNow()
213 }
214
215 // Test Bad Old Master passphrase, decrypt fail
216 _, err = UpdateMaster("masterpassphrase2", "incorrectmaster", 1, "secBoxv1$0$l8W69jygGur7sa0669mAJnIuYgjsbkx4wd+RdDzwIn2Z49FJurWkJDx2NA8g+ED9Nn6vGCLNFoHXSDIDeDBvJXouxs5zyX6mVozceVAVO7IadrL4+KKohV3MzoVlgodUYeNToOVB/5A=$4LZVjQ8P9pA=$32768$16$1$16384$8$1", DefaultParams)
217 if err != ErrSecretBoxDecryptFail {
218 t.Log(err)
219 t.Log("Expected decryption failure")
220 t.FailNow()
221 }
222}
223func TestUpdateMasterBadVersion(t *testing.T) {
224 output, err := Hash("password1234", "masterpassphrase", 0, ScryptParams{N: 32768, R: 16, P: 1}, DefaultParams)
225 if err != nil {

Callers

nothing calls this directly

Calls 3

HashFunction · 0.85
VerifyFunction · 0.85
UpdateMasterFunction · 0.85

Tested by

no test coverage detected