(t *testing.T)
| 399 | } |
| 400 | |
| 401 | func TestInitializeWithBlobCfgRetentionBlob(t *testing.T) { |
| 402 | ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant, repotesting.Options{ |
| 403 | NewRepositoryOptions: func(n *repo.NewRepositoryOptions) { |
| 404 | n.RetentionMode = blob.Governance |
| 405 | n.RetentionPeriod = time.Hour * 24 |
| 406 | }, |
| 407 | }) |
| 408 | |
| 409 | var d gather.WriteBuffer |
| 410 | defer d.Close() |
| 411 | |
| 412 | // verify that the blobcfg retention blob is created |
| 413 | require.NoError(t, env.RepositoryWriter.BlobStorage().GetBlob(ctx, format.KopiaBlobCfgBlobID, 0, -1, &d)) |
| 414 | require.NoError(t, env.RepositoryWriter.FormatManager().ChangePassword(ctx, "new-password")) |
| 415 | // verify that the blobcfg retention blob is created and is different after |
| 416 | // password-change |
| 417 | require.NoError(t, env.RepositoryWriter.BlobStorage().GetBlob(ctx, format.KopiaBlobCfgBlobID, 0, -1, &d)) |
| 418 | |
| 419 | // verify that we cannot re-initialize the repo even after password change |
| 420 | require.EqualError(t, repo.Initialize(testlogging.Context(t), env.RootStorage(), nil, env.Password), |
| 421 | "repository already initialized") |
| 422 | |
| 423 | // backup blobcfg blob |
| 424 | { |
| 425 | // backup & corrupt the blobcfg blob |
| 426 | d.Reset() |
| 427 | require.NoError(t, env.RepositoryWriter.BlobStorage().GetBlob(ctx, format.KopiaBlobCfgBlobID, 0, -1, &d)) |
| 428 | corruptedData := d.Dup() |
| 429 | corruptedData.Append([]byte("bad bits")) |
| 430 | require.NoError(t, env.RepositoryWriter.BlobStorage().PutBlob(ctx, format.KopiaBlobCfgBlobID, corruptedData.Bytes(), blob.PutOptions{})) |
| 431 | |
| 432 | // verify that we error out on corrupted blobcfg blob |
| 433 | _, err := repo.Open(ctx, env.ConfigFile(), env.Password, &repo.Options{}) |
| 434 | require.ErrorContains(t, err, "invalid repository password") |
| 435 | |
| 436 | // restore the original blob |
| 437 | require.NoError(t, env.RepositoryWriter.BlobStorage().PutBlob(ctx, format.KopiaBlobCfgBlobID, d.Bytes(), blob.PutOptions{})) |
| 438 | } |
| 439 | |
| 440 | // verify that we'd hard-fail on unexpected errors on blobcfg blob-puts |
| 441 | // when creating a new repository |
| 442 | require.EqualError(t, |
| 443 | repo.Initialize(testlogging.Context(t), |
| 444 | beforeop.NewWrapper( |
| 445 | env.RootStorage(), |
| 446 | // GetBlob callback |
| 447 | func(ctx context.Context, id blob.ID) error { |
| 448 | if id == format.KopiaBlobCfgBlobID { |
| 449 | return errors.New("unexpected error") |
| 450 | } |
| 451 | // simulate not-found for format-blob |
| 452 | if id == format.KopiaRepositoryBlobID { |
| 453 | return blob.ErrBlobNotFound |
| 454 | } |
| 455 | |
| 456 | return nil |
| 457 | }, nil, nil, nil, |
| 458 | ), |
nothing calls this directly
no test coverage detected