Page MenuHomePhabricator

mediawiki selenium gem creates a new user for every page created
Closed, InvalidPublic

Description

An instance that was previously working without problems now fails various tests due to permissioning problems caused by changes in https://gerrit.wikimedia.org/r/#/c/221313/5 which introduce user_factory. It should be possible to have an environment which doesn't use the user_factory

Errors include:

  • You do not have the right to create a new account (permdenied-createaccount) (MediawikiApi::ApiError)
  • You're not allowed to edit interface messages (protectednamespace-interface)
  • Certain tests made assumptions (wrongly or rightly) that the user would have things on their watchlist/or an edit count and tests fail due to this

To workaround I had to do $wgGroupPermissions['*']['createaccount'] = true;
( in my LocalSettings ($wgGroupPermissions['user']['createaccount'] = true; would not work)

Rights to create an account needed for page creation

Please can we
Report is as follows:

Feature: Notification

Background:                                 # features/notification.feature:4
You do not have the right to create a new account (permdenied-createaccount) (MediawikiApi::ApiError)
/var/lib/gems/2.1.0/gems/mediawiki_api-0.4.1/lib/mediawiki_api/client.rb:167:in `send_request'
/var/lib/gems/2.1.0/gems/mediawiki_api-0.4.1/lib/mediawiki_api/client.rb:188:in `raw_action'
/var/lib/gems/2.1.0/gems/mediawiki_api-0.4.1/lib/mediawiki_api/client.rb:30:in `action'
/var/lib/gems/2.1.0/gems/mediawiki_api-0.4.1/lib/mediawiki_api/client.rb:44:in `create_account'
/var/lib/gems/2.1.0/gems/mediawiki_selenium-1.4.0/lib/mediawiki_selenium/user_factory.rb:38:in `create_account'
/var/lib/gems/2.1.0/gems/mediawiki_selenium-1.4.0/lib/mediawiki_selenium/user_factory.rb:30:in `create'
/var/lib/gems/2.1.0/gems/mediawiki_selenium-1.4.0/lib/mediawiki_selenium/support/modules/user_factory_helper.rb:25:in `block (2 levels) in <module:UserFactoryHelper>'
/var/lib/gems/2.1.0/gems/mediawiki_selenium-1.4.0/lib/mediawiki_selenium/support/modules/api_helper.rb:17:in `api'
/var/lib/gems/2.1.0/gems/mediawiki_selenium-1.4.0/lib/mediawiki_selenium/support/hooks.rb:48:in `Before'

Event Timeline

Jdlrobson raised the priority of this task from to Needs Triage.
Jdlrobson updated the task description. (Show Details)
Jdlrobson subscribed.
Jdlrobson renamed this task from Rights to create an account needed for page creation in mediawiki selenium gem to Suddenly user rights needed in mediawiki selenium gem (?).Jul 20 2015, 6:25 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson set Security to None.

It looks like a new user is created for the purpose of page creation. We should not do this.. since some pages require certain rights to be edited... and this will result in a lot of user accounts.. @dduvall can you look at this promptly since Barry is broken without this..?

Jdlrobson renamed this task from Suddenly user rights needed in mediawiki selenium gem (?) to mediawiki selenium gem creates a new user for every page created .Jul 20 2015, 6:53 PM
Jdlrobson updated the task description. (Show Details)

I've created https://gerrit.wikimedia.org/r/225934 which should fail with the failures I am now getting with Barry

Seems to be caused by the upgrade in mediawiki selenium https://gerrit.wikimedia.org/r/#/c/221313/5/Gemfile
In mean time I've made it so Barry doesn't run bundle install so he will pass again.

dduvall claimed this task.

The user factory is opt-in; it's only enabled for environments where user_factory: true.

In this particular case, I believe the issue is a combination of the following. (TL;DR: Add an entry in environments.yml for Barry and set MEDIAWIKI_ENVIRONMENT=barry when you invoke Cucumber/MW-Selenium, and you should be good.)

  1. Your default environment is mw-vagrant-host so if you're not specifying a different MEDIAWIKI_ENVIRONMENT environment variable, you'll need to do that.
  2. The mw-vagrant-host environment is configured with the user factory enabled (I did this as part of that patch). This is probably a good thing as it affords the same level of isolation when testing locally that you'll get on CI, but you can remove it if you think the overabundance of newly created accounts on local vagrants will cause problems for devs. (In that case, sorry!)

I tried creating a new environment but it didn't work. The only way I can get barry to not use the user factory is to downgrade mediawiki selenium - are you sure there is not an underlying bug? Maybe we could pair on this today?

(also in general why does it need to do this for every page creation?) is a new user used for each test or for each run of cucumber)

I tried creating a new environment but it didn't work. The only way I can get barry to not use the user factory is to downgrade mediawiki selenium - are you sure there is not an underlying bug? Maybe we could pair on this today?

That's strange. Yes, let's definitely figure this out.

(also in general why does it need to do this for every page creation?) is a new user used for each test or for each run of cucumber)

When the user factory is enabled, a new user is created upon the first evaluation of user or password in each scenario. If an alternative user is referenced (user(:b) or as_user(:b) { ... }) then an additional account will be created for each.

Factories are an important part of writing deterministic tests as they let you set up the exact initial state that each test case requires, and it's important that this setup happen for each test case (scenario) and not the whole suite.[1][2] (Oy, two Martin Fowler references. I swear there are other people that have proven this. :) It's done via the API so it shouldn't add too much overhead. In fact, the greater isolation it affords will allow us to eventually run tests in parallel, likely yielding huge performance gains.

[1] http://martinfowler.com/bliki/ObjectMother.html
[2] http://martinfowler.com/articles/nonDeterminism.html#LackOfIsolation

We confirmed yesterday in IRC that configuration was the issue: MEDIAWIKI_ENVIRONMENT was not defined and so the default environment which has user_factory: true was being loaded.