Tests for Snippet backfill migration with ghost users
On my setup, I get these two failures:
~/heptapod/hdk/hdk-test/gitlab $ bin/rspec spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
(...)
Failures:
1) Gitlab::BackgroundMigration::BackfillSnippetRepositories#perform when snippet has an empty repo behaves like commits the file to the repository when author cannot update snippet or use git when user is a ghost behaves like migration_bot user commits files is expected to eq "GitLab Migration Bot"
Failure/Error: expect(last_commit.author_name).to eq migration_bot.name
expected: "GitLab Migration Bot"
got: "Test"
(compared using ==)
Shared Example Group: "migration_bot user commits files" called from ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:121
Shared Example Group: "commits the file to the repository" called from ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:131
# ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:82:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (3 levels) in <top (required)>'
# ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
# ./spec/spec_helper.rb:299:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:295:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:295:in `block (2 levels) in <top (required)>'
# ./spec/support/database_cleaner.rb:60:in `block (2 levels) in <main>'
2) Gitlab::BackgroundMigration::BackfillSnippetRepositories#perform when snippet does not have a repository behaves like commits the file to the repository when author cannot update snippet or use git when user is a ghost behaves like migration_bot user commits files is expected to eq "GitLab Migration Bot"
Failure/Error: expect(last_commit.author_name).to eq migration_bot.name
expected: "GitLab Migration Bot"
got: "Test"
(compared using ==)
Shared Example Group: "migration_bot user commits files" called from ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:121
Shared Example Group: "commits the file to the repository" called from ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:141
# ./spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb:82:in `block (4 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (3 levels) in <top (required)>'
# ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
# ./spec/spec_helper.rb:299:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:295:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:295:in `block (2 levels) in <top (required)>'
# ./spec/support/database_cleaner.rb:60:in `block (2 levels) in <main>'
Finished in 18.63 seconds (files took 19.39 seconds to load)
2 examples, 2 failures
Investigation shows that in the relevant commit_author
of BackfillSnippetRepositories, snippet.author.user_type
is not the expected "ghost"
while running these two tests.
This suggests a fixture problem; forcing user_type
without any other change makes the test pass.
TL;DR it's not the permission bypass one could fear (I'll add a specific test for that).