Project

General

Profile

Bug #12143

Plugin permissions not available during tests

Added by Stephen Benjamin over 6 years ago. Updated over 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Plugin integration
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

Description

The security block is evaluated at rails start up, but the permissions aren't available in a test.

1. Install foreman_salt

2. Throw a binding.pry in app/services/foreman/plugin.rb

204:   Permission.where(:name => name).first_or_create(:resource_type => options[:resource_type])
=> 205: binding.pry if name.to_s == 'view_salt_environments'

3. In a test, binding.pry there too

4. Run the test. You can confirm the Permission exists when the plugin is loaded, but in the actual test, it's no longer there

Something with transactions or fixtures?


Related issues

Related to Foreman - Bug #16821: AccessPermissionsTest does not pick up plugin permissionsClosed2016-10-06

History

#1 Updated by Dominic Cleal over 6 years ago

Test databases are always cleaned and then fixtures loaded, so you'll need to add any permissions into fixtures too, or create them on the fly (Permission.create, FG), as it stands.

#11206 added a method into the plugin definition to return which roles and permissions were registered, so you may be able to use this to recreate the permissions - or test that they're correct.

#2 Updated by Stephen Benjamin over 6 years ago

Oh, I didn't realize fixtures would reset the whole database, I figured it'd use transactions intelligently and keep the database at the initial state at the beginning of each test. I don't want to use fixtures in foreman_salt, but using FG works fine.

You can close this if you want.

#3 Updated by Dominic Cleal over 6 years ago

It's less that fixtures cause the reset, just that Rails starts with an empty test database and either it, and/or database_cleaner cause the reset. Fixtures get loaded after, plus any setup mechanisms in the test (which could call FG).

I'll leave it open for now, unless you wish to close it, because I agree that Foreman could help more here, perhaps by (optionally?) populating permissions in the test setup. foreman_salt isn't the only plugin that has hit this problem when writing tests that depend on permissions, because I think it's been mentioned in foreman_discovery too.

#4 Updated by Dominic Cleal over 5 years ago

  • Related to Bug #16821: AccessPermissionsTest does not pick up plugin permissions added

#5 Updated by Dominic Cleal over 5 years ago

  • Status changed from New to Ready For Testing

#16821 added this functionality, permissions registered by plugins are now initialised in the test environment.

#6 Updated by Dominic Cleal over 5 years ago

  • Status changed from Ready For Testing to Resolved

Also available in: Atom PDF