/test/assent/strategies/gitlab_test.exs

https://github.com/pow-auth/assent · Elixir · 65 lines · 59 code · 5 blank · 1 comment · 2 complexity · 9b4bc9675fe27b9ba087f7e7495b4b3a MD5 · raw file

  1. defmodule Assent.Strategy.GitlabTest do
  2. use Assent.Test.OAuth2TestCase
  3. alias Assent.Strategy.Gitlab
  4. # From https://docs.gitlab.com/ee/api/users.html#list-current-user-for-normal-users
  5. @user_response %{
  6. "id" => 1,
  7. "username" => "john_smith",
  8. "email" => "john@example.com",
  9. "name" => "John Smith",
  10. "state" => "active",
  11. "avatar_url" => "http://localhost:3000/uploads/user/avatar/1/index.jpg",
  12. "web_url" => "http://localhost:3000/john_smith",
  13. "created_at" => "2012-05-23T08:00:58Z",
  14. "bio" => nil,
  15. "location" => nil,
  16. "public_email" => "john@example.com",
  17. "skype" => "",
  18. "linkedin" => "",
  19. "twitter" => "",
  20. "website_url" => "",
  21. "organization" => "",
  22. "last_sign_in_at" => "2012-06-01T11:41:01Z",
  23. "confirmed_at" => "2012-05-23T09:05:22Z",
  24. "theme_id" => 1,
  25. "last_activity_on" => "2012-05-23",
  26. "color_scheme_id" => 2,
  27. "projects_limit" => 100,
  28. "current_sign_in_at" => "2012-06-02T06:36:55Z",
  29. "identities" => [
  30. %{"provider" => "github", "extern_uid" => "2435223452345"},
  31. %{"provider" => "bitbucket", "extern_uid" => "john_smith"},
  32. %{"provider" => "google_oauth2", "extern_uid" => "8776128412476123468721346"}
  33. ],
  34. "can_create_group" => true,
  35. "can_create_project" => true,
  36. "two_factor_enabled" => true,
  37. "external" => false,
  38. "private_profile" => false
  39. }
  40. @user %{
  41. "email" => "john@example.com",
  42. "email_verified" => true,
  43. "name" => "John Smith",
  44. "picture" => "http://localhost:3000/uploads/user/avatar/1/index.jpg",
  45. "preferred_username" => "john_smith",
  46. "sub" => 1
  47. }
  48. test "authorize_url/2", %{config: config} do
  49. assert {:ok, %{url: url}} = Gitlab.authorize_url(config)
  50. assert url =~ "/oauth/authorize?client_id="
  51. end
  52. test "callback/2", %{config: config, callback_params: params, bypass: bypass} do
  53. expect_oauth2_access_token_request(bypass, [uri: "/oauth/token"], fn _conn, params ->
  54. assert params["client_secret"] == config[:client_secret]
  55. end)
  56. expect_oauth2_user_request(bypass, @user_response, uri: "/api/v4/user")
  57. assert {:ok, %{user: user}} = Gitlab.callback(config, params)
  58. assert user == @user
  59. end
  60. end