API client creation needs to sign in with the correct user
What is the current situation
The API Client creation is used for Resource creation where we need to use the API as another user. An example would be the creation of a Fork as another user:
@api_client = Runtime::API::Client.new(:gitlab, is_new_session: false, user: user)
This is no problem on nightly
and staging
but is a big Issue on canary
and production
since there we do not have the ability to create everything using the admin API Token. Because of this, we need to log out and log in as the fork-creating user. Currently, this is not happening.
# in Resource::PersonalAccessToken
def fabricate!
Flow::Login.sign_in_unless_signed_in(as: user)
Page::Main::Menu.perform(&:click_edit_profile_link)
Page::Profile::Menu.perform(&:click_access_tokens)
...
The method sign_in_unless_signed_in does not check if the user is not logged in, but only if a user is logged in.
def sign_in_unless_signed_in(as: nil, address: :gitlab)
sign_in(as: as, address: address) unless Page::Main::Menu.perform(&:signed_in?)
end
What are possible solutions?
We need to be careful here, since this is used by many of our tests, and any changes need to be tracked meticulously to see if any other tests are failing due to changes. We can not just set this to always sign out and sign in, since that would lead to LDAP tests failing and the testing duration would increase.
We need a way of checking if the needed user is logged in and if not, log that user out and log in as the correct one.
Relevant Links
- Issue where this was found: #342599 (closed)
- Merge Request that created a first workaround: !72184 (merged)
- Needs to be removed!