Bug #16821
closedAccessPermissionsTest does not pick up plugin permissions
Description
All of the plugins that use permissions are now failing. AccessPermissionsTest in core attempts to look for a Permission for the plugins' routes but it never succeeds.
Here's why:
During plugin initialization the engine calls 'permission' to register permissions in the db: https://github.com/theforeman/foreman_discovery/blob/develop/lib/foreman_discovery/engine.rb#L49
'permission' in core will not run because there are pending migrations: https://github.com/theforeman/foreman/blob/develop/app/services/foreman/plugin.rb#L219
The test checks in the database for those permissions, so it fails. It used to work before #16557 because the 'test:lib' task ran after 'test:unit', and on the 2nd Rails initialization, there were no 'pending_migrations' so permissions from plugins were added just fine.
A few possible solutions:
- Modify the task in foreman-infra so that it runs 'RAILS_ENV=test rake db:migrate' prior to running tests. Currently Foreman kind of does this in the background via this setting (https://github.com/theforeman/foreman/blob/develop/config/environments/test.rb#L59) but it happens after plugins initialization, so during the 'permission' calls there are still pending migrations.
- Call ActiveRecord::Migration.maintain_test_schema! at some point before plugin initialization
- Modify the code so that permissions can be added even if there are pending_migrations (bad idea as the table may not exist)
- Add plugin permissions via fixtures (we'd have to do this in all plugins now, and adding fixtures in plugins is annoying)
Updated by Dominic Cleal about 8 years ago
- Related to Refactor #16557: Move tests into test/models, controllers, helpers dirs. added
Updated by The Foreman Bot about 8 years ago
- Status changed from New to Ready For Testing
- Assignee set to Adam Ruzicka
- Pull request https://github.com/theforeman/foreman/pull/3933 added
Updated by The Foreman Bot about 8 years ago
- Pull request https://github.com/theforeman/foreman/pull/3939 added
Updated by Dominic Cleal about 8 years ago
This is less about permissions in the database, because AccessControl (which is what's being tested in AccessPermissionsTest) doesn't use the Permission objects, it uses an in-memory control list. The AccessControl mapping isn't set up if there are pending migrations, which should only really prevent the Permission record being created.
Updated by Dominic Cleal about 8 years ago
- Assignee changed from Adam Ruzicka to Dominic Cleal
- Translation missing: en.field_release set to 189
Updated by Dominic Cleal about 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset dc9bd44ffa85277f5cc20698730697ea6448d2c9.
Updated by Dominic Cleal about 8 years ago
- Related to Bug #12143: Plugin permissions not available during tests added