Commit Graph

23 Commits

Author SHA1 Message Date
Nick Thomas 10c072263b Enable Warden for the Grape API
The practical effect of this commit is to make the API check the Rails session
cookie for authentication details. If the cookie is present and valid, it will
be used to authenticate.

The API now has several authentication options for users. They follow in this
order of precedence:

* Authentication token
* Personal access token
* OAuth2 Bearer token (Doorkeeper - application access)
* Rails session cookie
2016-09-19 12:27:37 +01:00
Stan Hu 170885edd6 Add Sentry logging to API calls
Closes #21043
2016-08-24 12:09:51 -07:00
tiagonbotelho 1d268a89de adds second batch of tests changed to active tense 2016-08-09 15:11:39 +01:00
Robert Schilling 54d26c89f6 API: Expose 'developers_can_push' for branches 2016-07-19 11:11:56 +02:00
Rémy Coutable 2cf7f09b1e
Revert "Revert "Merge branch '18193-developers-can-merge' into 'master' ""
This reverts commit 530f5158e2.

See !4892.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-07-18 10:16:56 +02:00
Robert Speicher 530f5158e2 Revert "Merge branch '18193-developers-can-merge' into 'master' "
This reverts commit 9ca633eb4c, reversing
changes made to fb229bbf79.
2016-07-13 13:57:30 -05:00
Timothy Andrew 60245bbe22 Refactor `Gitlab::GitAccess`
1. Don't use case statements for dispatch anymore. This leads to a lot
   of duplication, and makes the logic harder to follow.

2. Remove duplicated logic.

    - For example, the `can_push_to_branch?` exists, but we also have a
      different way of checking the same condition within `change_access_check`.

    - This kind of duplication is removed, and the `can_push_to_branch?`
      method is used in both places.

3. Move checks returning true/false to `UserAccess`.

    - All public methods in `GitAccess` now return an instance of
      `GitAccessStatus`. Previously, some methods would return
      true/false as well, which was confusing.

    - It makes sense for these kinds of checks to be at the level of a
      user, so the `UserAccess` class was repurposed for this. The prior
      `UserAccess.allowed?` classmethod is converted into an instance
      method.

    - All external uses of these checks have been migrated to use the
      `UserAccess` class

4. Move the "change_access_check" into a separate class.

    - Create the `GitAccess::ChangeAccessCheck` class to run these
      checks, which are quite substantial.

    - `ChangeAccessCheck` returns an instance of `GitAccessStatus` as
      well.

5. Break out the boolean logic in `ChangeAccessCheck` into `if/else`
   chains - this seems more readable.

6. I can understand that this might look like overkill for !4892, but I
   think this is a good opportunity to clean it up.

    - http://martinfowler.com/bliki/OpportunisticRefactoring.html
2016-07-13 13:24:56 +05:30
Grzegorz Bizon 9e211091a8 Enable Style/EmptyLines cop, remove redundant ones 2016-07-01 21:56:17 +02:00
Timothy Andrew 9d7cda3ddc Fix `api_helpers_spec` 2016-06-16 12:28:31 +05:30
Timothy Andrew b22a47c62e Combine `API::Helpers::Core` and `API::Helpers::Authentication` back into `API::Helpers`
- Makes the MR easier to read; this can go in a separate MR
- This is a (sort of) revert of 99bea01
2016-04-28 22:28:36 +05:30
Timothy Andrew 1541d1de18 Rename `api_helpers_spec` to `api_authentication_spec`
- And fix all tests.
2016-04-28 22:28:36 +05:30
Jason Lee 3d613fe1e8 Fix API::APIHelpers -> API::Helpers;
Rails Autoload find file to require is use , APIHelpers -> api_helpers.rb, not helpers.rb;
2015-10-23 11:42:57 +08:00
Robert Speicher 0f627f1c60 Fix `raise_error` without an argument deprecation warnings 2015-06-22 12:13:47 +02:00
Robert Speicher 5a9ede4721 Update mock and stub syntax for specs 2015-06-22 12:13:46 +02:00
Jeroen van Baarsen 0c4a70a306 Updated rspec to rspec 3.x syntax
Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
2015-02-12 19:17:35 +01:00
Valery Sizov e41dadcb33 Doorkeeper integration 2014-12-24 15:38:07 +02:00
Jacob Vosmaer 2d8c310f11 Make user access test pass for the right reason
If we do not set a private token during the test, current_user will be
nil because the user is not found, not due to the access check.
2014-05-15 10:30:50 +02:00
Jacob Vosmaer 02b85fd236 Check user access status in API for current_user 2014-05-15 10:22:59 +02:00
Jacob Vosmaer 6d45909f03 Add test for current behavior of current_user 2014-05-15 09:57:21 +02:00
Jeroen van Baarsen 5dd2f36ae1 Added API testing group 2014-04-11 21:45:56 +02:00
Izaak Alpert fdc23a93e7 Style guide fixes (spacing)
Change-Id: I966bfd0ccc4b05925384ecab8c6cbe3c6ba3b667
2013-09-09 13:18:10 -04:00
Izaak Alpert 7a56075efa Some of the requested updates, rebase on master
Change-Id: I305266fe9acbbb5136adeeb52e7e4e1d6629a30a
2013-09-09 12:04:38 -04:00
Izaak Alpert e86e881832 API: admin users can sudo commands as other users
-Specifying a header of SUDO or adding a :sudo with either user id, or username of the user will set the current_user to be that user if your identifying private_token/PRIVATE_TOKEN is an administrator token
2013-09-09 12:04:38 -04:00