Project

General

Profile

Actions

Bug #16821

closed

AccessPermissionsTest does not pick up plugin permissions

Added by Daniel Lobato Garcia almost 8 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Tests
Target version:
Fixed in Releases:
Found in Releases:

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)

Related issues 2 (0 open2 closed)

Related to Foreman - Refactor #16557: Move tests into test/models, controllers, helpers dirs.ClosedDominic Cleal09/14/2016Actions
Related to Foreman - Bug #12143: Plugin permissions not available during testsResolved10/12/2015Actions
Actions #1

Updated by Dominic Cleal almost 8 years ago

  • Description updated (diff)
Actions #2

Updated by Dominic Cleal almost 8 years ago

  • Related to Refactor #16557: Move tests into test/models, controllers, helpers dirs. added
Actions #3

Updated by The Foreman Bot almost 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
Actions #4

Updated by The Foreman Bot almost 8 years ago

  • Pull request https://github.com/theforeman/foreman/pull/3939 added
Actions #5

Updated by Dominic Cleal almost 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.

Actions #6

Updated by Dominic Cleal almost 8 years ago

  • Assignee changed from Adam Ruzicka to Dominic Cleal
  • Translation missing: en.field_release set to 189
Actions #7

Updated by Dominic Cleal almost 8 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #8

Updated by Dominic Cleal over 7 years ago

  • Related to Bug #12143: Plugin permissions not available during tests added
Actions

Also available in: Atom PDF