auth0 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +50 -0
  3. data/.github/CODEOWNERS +1 -0
  4. data/.gitignore +0 -1
  5. data/CHANGELOG.md +27 -0
  6. data/DEPLOYMENT.md +11 -3
  7. data/Gemfile +2 -1
  8. data/Gemfile.lock +172 -0
  9. data/README.md +2 -2
  10. data/auth0.gemspec +1 -3
  11. data/codecov.yml +22 -0
  12. data/deploy_documentation.sh +1 -1
  13. data/lib/auth0/api/v2.rb +4 -0
  14. data/lib/auth0/api/v2/anomaly.rb +36 -0
  15. data/lib/auth0/api/v2/jobs.rb +22 -3
  16. data/lib/auth0/api/v2/roles.rb +172 -0
  17. data/lib/auth0/api/v2/users.rb +117 -4
  18. data/lib/auth0/exception.rb +33 -7
  19. data/lib/auth0/mixins/httpproxy.rb +10 -7
  20. data/lib/auth0/mixins/permission_struct.rb +3 -0
  21. data/lib/auth0/mixins/validation.rb +25 -0
  22. data/lib/auth0/version.rb +1 -1
  23. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_check_if_ip_is_blocked/should_return_200_response_code.yml +65 -0
  24. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_remove_ip_block/should_remove_an_IP_successfully.yml +60 -0
  25. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_at_least_1_result.yml +1 -1
  26. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_first_page_of_one_result.yml +1 -1
  27. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_test_client_grant.yml +1 -1
  28. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_delete_client_grant/should_delete_the_test_client_grant.yml +1 -1
  29. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_patch_client_grant/should_update_the_test_client_grant.yml +1 -1
  30. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client.yml +1 -1
  31. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client_grant.yml +1 -1
  32. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client.yml +1 -1
  33. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client_grant.yml +1 -1
  34. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_exclude_and_include_fields_properly.yml +1 -1
  35. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_include_the_specified_fields.yml +1 -1
  36. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/should_get_the_test_client.yml +1 -1
  37. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_fields_not_specified.yml +1 -1
  38. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_the_specified_fields.yml +1 -1
  39. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_include_the_specified_fields.yml +1 -1
  40. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_paginate_results.yml +1 -1
  41. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/should_get_at_least_one_client.yml +1 -1
  42. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_delete_client/should_delete_the_test_client_without_an_error.yml +1 -1
  43. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +1 -1
  44. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/create_test_client.yml +1 -1
  45. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_exclude_the_fields_indicated.yml +1 -1
  46. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_include_the_fields_indicated.yml +1 -1
  47. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/should_find_the_correct_connection.yml +1 -1
  48. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_include_previously-created_connection_when_filtered.yml +1 -1
  49. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_exclude_the_fields_indicated_from_filtered_results.yml +1 -1
  50. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_include_the_fields_indicated_from_filtered_results.yml +1 -1
  51. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_include_the_previously_created_connection.yml +1 -1
  52. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_not_be_empty.yml +1 -1
  53. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection/should_delete_the_connection.yml +1 -1
  54. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection_user/should_delete_the_user_created.yml +2 -2
  55. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +1 -1
  56. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_connection.yml +1 -1
  57. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_user.yml +1 -1
  58. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_user.yml +1 -1
  59. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_credential.yml +1 -1
  60. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_user.yml +1 -1
  61. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_configure_provider/should_configure_a_new_email_provider.yml +1 -1
  62. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_delete_the_existing_email_provider_without_an_error.yml +1 -1
  63. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_throw_an_error_trying_to_get_the_email_provider.yml +1 -1
  64. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_with_specific_fields.yml +1 -1
  65. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_without_specific_fields.yml +1 -1
  66. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/should_get_the_existing_email_provider.yml +1 -1
  67. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_update_provider/should_update_the_existing_email_provider.yml +1 -1
  68. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/delete_existing_provider.yml +1 -1
  69. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_match_the_created_log_entry.yml +2 -2
  70. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_not_be_empty.yml +2 -2
  71. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_fields_not_specified.yml +1 -1
  72. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_the_specified_fields.yml +1 -1
  73. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_have_one_log_entry.yml +1 -1
  74. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_include_the_specified_fields.yml +1 -1
  75. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_from/should_take_one_log_entry.yml +2 -2
  76. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/create_test_user.yml +1 -1
  77. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_disabled_rule.yml +1 -1
  78. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_enabled_rule.yml +1 -1
  79. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_user.yml +1 -1
  80. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_permissions/should_add_a_Permission_to_the_Role_successfully.yml +67 -0
  81. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_users/should_add_a_User_to_the_Role_successfully.yml +67 -0
  82. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_delete_role/should_delete_the_Role_successfully.yml +60 -0
  83. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role/should_get_the_Role_successfully.yml +65 -0
  84. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_exactly_1_Permission.yml +65 -0
  85. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_the_added_Permission_from_the_Role_successfully.yml +65 -0
  86. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_exactly_1_User.yml +65 -0
  87. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_the_added_User_from_the_Role_successfully.yml +65 -0
  88. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_roles/should_get_the_Role_successfully.yml +65 -0
  89. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_remove_role_permissions/should_remove_a_Permission_from_the_Role_successfully.yml +62 -0
  90. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_update_role/should_update_the_Role_successfully.yml +67 -0
  91. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_api.yml +67 -0
  92. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_role.yml +67 -0
  93. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_user.yml +67 -0
  94. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_api.yml +60 -0
  95. data/spec/fixtures/vcr_cassettes/{Auth0_Api_V2_Users/_delete_user/should_delete_the_user_successfully.yml → Auth0_Api_V2_Roles/delete_test_user.yml} +14 -8
  96. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_disabled_rule_without_an_error.yml +1 -1
  97. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_enabled_rule_without_an_error.yml +1 -1
  98. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_fields_not_specified.yml +1 -1
  99. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_specified_fields.yml +1 -1
  100. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_include_the_specified_fields.yml +1 -1
  101. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/should_get_a_specific_rule.yml +1 -1
  102. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_exclude_fields_not_specified.yml +1 -1
  103. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_include_the_specified_fields.yml +1 -1
  104. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_disabled_rule.yml +1 -1
  105. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_enabled_rule.yml +1 -1
  106. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_paginated_results.yml +2 -2
  107. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/should_return_at_least_1_rule.yml +1 -1
  108. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +1 -1
  109. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_disabled_rule.yml +1 -1
  110. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_enabled_rule.yml +1 -1
  111. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_active_users/should_have_at_least_one_active_user.yml +1 -1
  112. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_daily_stats/should_have_at_least_one_stats_entry_for_the_timeframe.yml +1 -1
  113. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings/should_get_the_tenant_settings.yml +1 -1
  114. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_exclude_a_field_not_requested.yml +1 -1
  115. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_include_the_field_requested.yml +1 -1
  116. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +1 -1
  117. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_update_the_tenant_settings_with_a_new_tenant_name.yml +1 -1
  118. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_email_verification/should_create_an_email_verification_ticket.yml +1 -1
  119. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_password_change/should_create_a_password_change_ticket.yml +1 -1
  120. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/create_test_user.yml +1 -1
  121. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/delete_test_user.yml +1 -1
  122. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_permissions/should_add_a_Permissions_for_a_User_successfully.yml +67 -0
  123. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +62 -0
  124. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_User_successfully.yml +60 -0
  125. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_secondary_User_successfully.yml +60 -0
  126. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user_provider/should_attempt_to_delete_the_MFA_provider_for_the_User.yml +60 -0
  127. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_enrollments/should_get_Enrollments_for_a_User_successfully.yml +65 -0
  128. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_exactly_1_Permission_for_a_User_successfully.yml +65 -0
  129. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_the_correct_Permission_for_a_User_successfully.yml +65 -0
  130. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_roles/should_get_Roles_for_a_User_successfully.yml +65 -0
  131. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_invalidate_browsers/should_invalidate_MFA_browsers_for_the_User_successfully.yml +62 -0
  132. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_link_user_account/should_link_two_Users_successfully.yml +67 -0
  133. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +68 -0
  134. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_permissions/should_remove_a_Permission_from_a_User_successfully.yml +62 -0
  135. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_roles/should_remove_a_Role_from_a_User_successfully.yml +62 -0
  136. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_unlink_user_account/should_unlink_two_Users_successfully.yml +65 -0
  137. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_fields_not_indicated.yml +15 -10
  138. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_the_fields_indicated.yml +15 -13
  139. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_include_the_fields_indicated.yml +15 -13
  140. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/should_retrieve_the_created_user.yml +15 -16
  141. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user_logs/should_get_Logs_for_a_User_successfully.yml +69 -0
  142. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v2_search_engine_query.yml +14 -8
  143. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v3_search_engine_query.yml +14 -8
  144. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_exclude_the_indicated_fields_when_paginated.yml +13 -7
  145. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_include_the_indicated_fields_when_paginated.yml +13 -7
  146. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_not_include_other_fields_when_paginated.yml +13 -7
  147. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_return_the_correct_number_of_results_when_paginated.yml +13 -7
  148. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/should_have_at_least_one_user.yml +13 -7
  149. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_secondary_test_user.yml +67 -0
  150. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_api.yml +67 -0
  151. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_role.yml +67 -0
  152. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_user.yml +15 -16
  153. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_api.yml +60 -0
  154. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_role.yml +60 -0
  155. data/spec/integration/lib/auth0/api/v2/api_anomaly_spec.rb +17 -0
  156. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +145 -0
  157. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +150 -32
  158. data/spec/integration/lib/auth0/auth0_client_spec.rb +3 -4
  159. data/spec/lib/auth0/api/v2/anomaly_spec.rb +26 -0
  160. data/spec/lib/auth0/api/v2/jobs_spec.rb +33 -1
  161. data/spec/lib/auth0/api/v2/roles_spec.rb +360 -0
  162. data/spec/lib/auth0/api/v2/users_spec.rb +406 -66
  163. data/spec/lib/auth0/mixins/httpproxy_spec.rb +57 -0
  164. data/spec/spec_helper.rb +5 -6
  165. data/spec/support/credentials.rb +4 -13
  166. data/spec/support/dummy_class.rb +1 -1
  167. data/spec/support/stub_response.rb +1 -1
  168. metadata +96 -10
  169. data/.travis.yml +0 -18
  170. data/build_travis.sh +0 -7
  171. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_email_verified_and_return_the_updated_data.yml +0 -68
  172. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_user_metadata_and_return_the_updated_user.yml +0 -69
@@ -0,0 +1,360 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Roles do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Roles)
6
+ @instance = dummy_instance
7
+ end
8
+
9
+ context '.get_roles' do
10
+ it 'is expected to exist' do
11
+ expect(@instance).to respond_to(:get_roles)
12
+ end
13
+
14
+ it 'is expected to have a roles alias' do
15
+ expect(@instance).to respond_to(:roles)
16
+ end
17
+
18
+ it 'is expected to get Roles with default parameters' do
19
+ expect(@instance).to receive(:get).with(
20
+ '/api/v2/roles',
21
+ per_page: nil,
22
+ page: nil,
23
+ include_totals: nil
24
+ )
25
+ expect { @instance.get_roles }.not_to raise_error
26
+ end
27
+
28
+ it 'is expected to get Roles with custom parameters' do
29
+ expect(@instance).to receive(:get).with(
30
+ '/api/v2/roles',
31
+ per_page: 10,
32
+ page: 3,
33
+ include_totals: true
34
+ )
35
+ expect do
36
+ @instance.get_roles(per_page: 10, page: 3, include_totals: true)
37
+ end.not_to raise_error
38
+ end
39
+ end
40
+
41
+ context '.get_role' do
42
+ it 'is expected to exist' do
43
+ expect(@instance).to respond_to(:get_role)
44
+ end
45
+
46
+ it 'is expected to have a role alias' do
47
+ expect(@instance).to respond_to(:role)
48
+ end
49
+
50
+ it 'is expected to raise an exception if an empty Role ID is passed' do
51
+ expect(@instance).not_to receive(:get)
52
+ expect do
53
+ @instance.get_role('')
54
+ end.to raise_exception Auth0::MissingParameter
55
+ end
56
+
57
+ it 'is expected to get a Role by ID' do
58
+ expect(@instance).to receive(:get).with('/api/v2/roles/ROLE_ID')
59
+ expect { @instance.get_role('ROLE_ID') }.not_to raise_error
60
+ end
61
+ end
62
+
63
+ context '.create_role' do
64
+ it 'is expected to exist' do
65
+ expect(@instance).to respond_to(:create_role)
66
+ end
67
+
68
+ it 'is expected to raise an exception if an empty Role name is passed' do
69
+ expect(@instance).not_to receive(:post)
70
+ expect do
71
+ @instance.create_role('')
72
+ end.to raise_exception Auth0::MissingParameter
73
+ end
74
+
75
+ it 'is expected to post a new Role' do
76
+ expect(@instance).to receive(:post).with(
77
+ '/api/v2/roles',
78
+ name: 'ROLE_NAME',
79
+ description: 'ROLE_DESCRIPTION'
80
+ )
81
+ expect do
82
+ @instance.create_role(
83
+ 'ROLE_NAME',
84
+ description: 'ROLE_DESCRIPTION'
85
+ )
86
+ end.not_to raise_error
87
+ end
88
+ end
89
+
90
+ context '.update_role' do
91
+ it 'is expected to exist' do
92
+ expect(@instance).to respond_to(:update_role)
93
+ end
94
+
95
+ it 'is expected to raise an exception if an empty Role ID is passed' do
96
+ expect(@instance).not_to receive(:patch)
97
+ expect do
98
+ @instance.update_role('')
99
+ end.to raise_exception Auth0::MissingParameter
100
+ end
101
+
102
+ it 'is expected to post an updated Role' do
103
+ expect(@instance).to receive(:patch).with(
104
+ '/api/v2/roles/ROLE_ID',
105
+ name: 'ROLE_NAME',
106
+ description: 'ROLE_DESCRIPTION'
107
+ )
108
+ expect do
109
+ @instance.update_role(
110
+ 'ROLE_ID',
111
+ name: 'ROLE_NAME',
112
+ description: 'ROLE_DESCRIPTION'
113
+ )
114
+ end.not_to raise_error
115
+ end
116
+ end
117
+
118
+ context '.delete_role' do
119
+ it 'is expected to exist' do
120
+ expect(@instance).to respond_to(:delete_role)
121
+ end
122
+
123
+ it 'is expected to raise an exception if an empty Role ID is passed' do
124
+ expect(@instance).not_to receive(:delete)
125
+ expect do
126
+ @instance.delete_role('')
127
+ end.to raise_exception Auth0::MissingParameter
128
+ end
129
+
130
+ it 'is expected to delete a Role' do
131
+ expect(@instance).to receive(:delete).with('/api/v2/roles/ROLE_ID')
132
+ expect { @instance.delete_role('ROLE_ID') }.not_to raise_error
133
+ end
134
+ end
135
+
136
+ context '.get_users' do
137
+ it 'is expected to exist' do
138
+ expect(@instance).to respond_to(:get_role_users)
139
+ end
140
+
141
+ it 'is expected to raise an exception if an empty Role ID is passed' do
142
+ expect(@instance).not_to receive(:get)
143
+ expect do
144
+ @instance.get_role_users('')
145
+ end.to raise_exception Auth0::MissingParameter
146
+ end
147
+
148
+ it 'is expected to get Users for a Role with default parameters' do
149
+ expect(@instance).to receive(:get).with(
150
+ '/api/v2/roles/ROLE_ID/users',
151
+ per_page: nil,
152
+ page: nil,
153
+ include_totals: nil
154
+ )
155
+ expect { @instance.get_role_users('ROLE_ID') }.not_to raise_error
156
+ end
157
+
158
+ it 'is expected to get Users for a Role with custom parameters' do
159
+ expect(@instance).to receive(:get).with(
160
+ '/api/v2/roles/ROLE_ID/users',
161
+ per_page: 30,
162
+ page: 4,
163
+ include_totals: true
164
+ )
165
+ expect do
166
+ @instance.get_role_users('ROLE_ID', per_page: 30, page: 4, include_totals: true)
167
+ end.not_to raise_error
168
+ end
169
+ end
170
+
171
+ context '.add_users' do
172
+ it 'is expected to exist' do
173
+ expect(@instance).to respond_to(:add_role_users)
174
+ end
175
+
176
+ it 'is expected to raise an exception if an empty Role ID is passed' do
177
+ expect(@instance).not_to receive(:post)
178
+ expect do
179
+ @instance.add_role_users('', [])
180
+ end.to raise_exception Auth0::MissingParameter
181
+ end
182
+
183
+ it 'is expected to raise an exception if an array is not passed for Users' do
184
+ expect(@instance).not_to receive(:post)
185
+ expect do
186
+ @instance.add_role_users('ROLE_ID', 'USERS')
187
+ end.to raise_exception Auth0::InvalidParameter
188
+ end
189
+
190
+ it 'is expected to raise an exception if no User IDs are passed' do
191
+ expect(@instance).not_to receive(:post)
192
+ expect do
193
+ @instance.add_role_users('ROLE_ID', [])
194
+ end.to raise_exception Auth0::MissingParameter
195
+ end
196
+
197
+ it 'is expected to add Users to a Role' do
198
+ expect(@instance).to receive(:post).with(
199
+ '/api/v2/roles/ROLE_ID/users',
200
+ users: %w[test|user-01 test|user-02]
201
+ )
202
+ expect do
203
+ @instance.add_role_users('ROLE_ID', %w[test|user-01 test|user-02])
204
+ end.not_to raise_error
205
+ end
206
+ end
207
+
208
+ context '.get_permissions' do
209
+ it 'is expected to exist' do
210
+ expect(@instance).to respond_to(:get_role_permissions)
211
+ end
212
+
213
+ it 'is expected to raise an exception if an empty Role ID is passed' do
214
+ expect(@instance).not_to receive(:get)
215
+ expect do
216
+ @instance.get_role_permissions('')
217
+ end.to raise_exception Auth0::MissingParameter
218
+ end
219
+
220
+ it 'is expected to get Roles with default parameters' do
221
+ expect(@instance).to receive(:get).with(
222
+ '/api/v2/roles/ROLE_ID/permissions',
223
+ per_page: nil,
224
+ page: nil,
225
+ include_totals: nil
226
+ )
227
+ expect { @instance.get_role_permissions('ROLE_ID') }.not_to raise_error
228
+ end
229
+
230
+ it 'is expected to get Roles with custom parameters' do
231
+ expect(@instance).to receive(:get).with(
232
+ '/api/v2/roles/ROLE_ID/permissions',
233
+ per_page: 15,
234
+ page: 5,
235
+ include_totals: true
236
+ )
237
+ expect do
238
+ @instance.get_role_permissions('ROLE_ID', per_page: 15, page: 5, include_totals: true)
239
+ end.not_to raise_error
240
+ end
241
+ end
242
+
243
+ context '.add_permissions' do
244
+ it 'is expected to exist' do
245
+ expect(@instance).to respond_to(:add_role_permissions)
246
+ end
247
+
248
+ it 'is expected to raise an exception if an empty Role ID is passed' do
249
+ expect(@instance).not_to receive(:post)
250
+ expect do
251
+ @instance.add_role_permissions('', [])
252
+ end.to raise_exception Auth0::MissingParameter
253
+ end
254
+
255
+ it 'is expected to raise an exception if an array is not passed for permissions' do
256
+ expect(@instance).not_to receive(:post)
257
+ expect do
258
+ @instance.add_role_permissions('ROLE_ID', 'PERMISSIONS')
259
+ end.to raise_exception Auth0::InvalidParameter
260
+ end
261
+
262
+ it 'is expected to raise an exception if an empty permissions array is passed' do
263
+ expect(@instance).not_to receive(:post)
264
+ expect do
265
+ @instance.add_role_permissions('ROLE_ID', [])
266
+ end.to raise_exception Auth0::MissingParameter
267
+ end
268
+
269
+ it 'is expected to raise an exception if the permissions array does not contain Permission structs' do
270
+ expect(@instance).not_to receive(:post)
271
+ expect do
272
+ @instance.add_role_permissions('ROLE_ID', [1, 2, 3])
273
+ end.to raise_exception Auth0::InvalidParameter
274
+ end
275
+
276
+ it 'is expected to add permissions to a Role' do
277
+ expect(@instance).to receive(:post).with(
278
+ '/api/v2/roles/ROLE_ID/permissions',
279
+ permissions: [
280
+ {
281
+ permission_name: 'permission-name-1',
282
+ resource_server_identifier: 'server-id-1'
283
+ },
284
+ {
285
+ permission_name: 'permission-name-2',
286
+ resource_server_identifier: 'server-id-2'
287
+ }
288
+ ]
289
+ )
290
+ expect do
291
+ @instance.add_role_permissions(
292
+ 'ROLE_ID',
293
+ [
294
+ Permission.new('permission-name-1', 'server-id-1'),
295
+ Permission.new('permission-name-2', 'server-id-2')
296
+ ]
297
+ )
298
+ end.not_to raise_error
299
+ end
300
+ end
301
+
302
+ context '.remove_permissions' do
303
+ it 'is expected to exist' do
304
+ expect(@instance).to respond_to(:remove_role_permissions)
305
+ end
306
+
307
+ it 'is expected to raise an exception if an empty Role ID is passed' do
308
+ expect(@instance).not_to receive(:delete_with_body)
309
+ expect do
310
+ @instance.remove_role_permissions('', [])
311
+ end.to raise_exception Auth0::MissingParameter
312
+ end
313
+
314
+ it 'is expected to raise an exception if an array is not passed for permissions' do
315
+ expect(@instance).not_to receive(:post)
316
+ expect do
317
+ @instance.remove_role_permissions('ROLE_ID', 'PERMISSIONS')
318
+ end.to raise_exception Auth0::InvalidParameter
319
+ end
320
+
321
+ it 'is expected to raise an exception if an empty permissions array is passed' do
322
+ expect(@instance).not_to receive(:delete_with_body)
323
+ expect do
324
+ @instance.remove_role_permissions('ROLE_ID', [])
325
+ end.to raise_exception Auth0::MissingParameter
326
+ end
327
+
328
+ it 'is expected to raise an exception if the permissions array does not contain Permission structs' do
329
+ expect(@instance).not_to receive(:post)
330
+ expect do
331
+ @instance.remove_role_permissions('ROLE_ID', [1, 2, 3])
332
+ end.to raise_exception Auth0::InvalidParameter
333
+ end
334
+
335
+ it 'is expected to remove permissions from a Role' do
336
+ expect(@instance).to receive(:delete_with_body).with(
337
+ '/api/v2/roles/ROLE_ID/permissions',
338
+ permissions: [
339
+ {
340
+ permission_name: 'permission-name-3',
341
+ resource_server_identifier: 'server-id-3'
342
+ },
343
+ {
344
+ permission_name: 'permission-name-4',
345
+ resource_server_identifier: 'server-id-4'
346
+ }
347
+ ]
348
+ )
349
+ expect do
350
+ @instance.remove_role_permissions(
351
+ 'ROLE_ID',
352
+ [
353
+ Permission.new('permission-name-3', 'server-id-3'),
354
+ Permission.new('permission-name-4', 'server-id-4')
355
+ ]
356
+ )
357
+ end.not_to raise_error
358
+ end
359
+ end
360
+ end
@@ -7,10 +7,15 @@ describe Auth0::Api::V2::Users do
7
7
  end
8
8
 
9
9
  context '.users' do
10
- it { expect(@instance).to respond_to(:users) }
11
- it { expect(@instance).to respond_to(:get_users) }
10
+ it 'is expected to respond to a users method' do
11
+ expect(@instance).to respond_to(:users)
12
+ end
13
+
14
+ it 'is expected to respond to a get_users method' do
15
+ expect(@instance).to respond_to(:get_users)
16
+ end
12
17
 
13
- it 'is expected to call /api/v2/users' do
18
+ it 'is expected to get /api/v2/users' do
14
19
  expect(@instance).to receive(:get).with(
15
20
  '/api/v2/users',
16
21
  per_page: nil,
@@ -26,35 +31,57 @@ describe Auth0::Api::V2::Users do
26
31
  expect { @instance.users }.not_to raise_error
27
32
  end
28
33
 
29
- it 'is expected to call /api/v2/users with a search engine' do
34
+ it 'is expected to get /api/v2/users with custom parameters' do
30
35
  expect(@instance).to receive(:get).with(
31
36
  '/api/v2/users',
32
- per_page: nil,
33
- page: nil,
34
- include_totals: nil,
37
+ per_page: 10,
38
+ page: 1,
39
+ include_totals: true,
35
40
  sort: nil,
36
- connection: nil,
37
- fields: nil,
41
+ connection: 'auth0',
42
+ fields: 'name,email',
38
43
  include_fields: nil,
39
44
  q: nil,
40
45
  search_engine: 'v3'
41
46
  )
42
- expect { @instance.users(search_engine: 'v3') }.not_to raise_error
47
+ expect do
48
+ @instance.users(
49
+ search_engine: 'v3',
50
+ per_page: 10,
51
+ page: 1,
52
+ include_totals: true,
53
+ connection: 'auth0',
54
+ fields: 'name,email'
55
+ )
56
+ end.not_to raise_error
43
57
  end
44
58
  end
45
59
 
46
60
  context '.user' do
47
- it { expect(@instance).to respond_to(:user) }
61
+ it 'is expected to respond to a user method' do
62
+ expect(@instance).to respond_to(:user)
63
+ end
64
+
48
65
  it 'is expected to call get request to /api/v2/users/USER_ID' do
49
- expect(@instance).to receive(:get).with('/api/v2/users/USER_ID', fields: nil, include_fields: true)
66
+ expect(@instance).to receive(:get).with(
67
+ '/api/v2/users/USER_ID',
68
+ fields: nil,
69
+ include_fields: true
70
+ )
50
71
  expect { @instance.user('USER_ID') }.not_to raise_error
51
72
  end
52
- it { expect { @instance.user('') }.to raise_error 'Must supply a valid user_id' }
73
+
74
+ it 'is expected to raise an exception when the user ID is empty' do
75
+ expect { @instance.user(nil) }.to raise_exception(Auth0::MissingUserId)
76
+ end
53
77
  end
54
78
 
55
79
  context '.create_user' do
56
- it { expect(@instance).to respond_to(:create_user) }
57
- it 'is expected to call post to /api/v2/users' do
80
+ it 'is expected to respond to a create_user method' do
81
+ expect(@instance).to respond_to(:create_user)
82
+ end
83
+
84
+ it 'is expected to post to /api/v2/users' do
58
85
  expect(@instance).to receive(:post).with(
59
86
  '/api/v2/users',
60
87
  email: 'test@test.com',
@@ -62,107 +89,163 @@ describe Auth0::Api::V2::Users do
62
89
  connection: 'conn',
63
90
  name: 'name'
64
91
  )
65
- @instance.create_user(
66
- 'name',
67
- email: 'test@test.com',
68
- password: 'password',
69
- connection: 'conn'
70
- )
92
+ expect do
93
+ @instance.create_user(
94
+ 'name',
95
+ email: 'test@test.com',
96
+ password: 'password',
97
+ connection: 'conn'
98
+ )
99
+ end.not_to raise_error
71
100
  end
72
101
  end
73
102
 
74
103
  context '.delete_users' do
75
- it { expect(@instance).to respond_to :delete_users }
104
+ it 'is expected to respond to a delete_users method' do
105
+ expect(@instance).to respond_to :delete_users
106
+ end
107
+
76
108
  it 'is expected to call delete to /api/v2/users' do
77
109
  expect(@instance).to receive(:delete).with('/api/v2/users')
78
- @instance.delete_users
110
+ expect { @instance.delete_users }.not_to raise_error
79
111
  end
80
112
  end
81
113
 
82
114
  context '.delete_user' do
83
- it { expect(@instance).to respond_to(:delete_user) }
84
- it 'is expected to call delete to /api/v2/users/userId' do
85
- expect(@instance).to receive(:delete).with('/api/v2/users/userId')
86
- @instance.delete_user('userId')
115
+ it 'is expected to respond to a delete_user method' do
116
+ expect(@instance).to respond_to(:delete_user)
87
117
  end
88
118
 
89
- it 'is expected not to call delete to /api/v2/users if user_id is blank' do
119
+ it 'is expected to delete /api/v2/users/USER_ID' do
120
+ expect(@instance).to receive(:delete).with('/api/v2/users/USER_ID')
121
+ @instance.delete_user('USER_ID')
122
+ end
123
+
124
+ it 'is expected not to delete /api/v2/users if user_id is blank' do
90
125
  expect(@instance).not_to receive(:delete)
91
- expect { @instance.delete_user('') }.to raise_exception(
126
+ expect { @instance.delete_user(nil) }.to raise_exception(
92
127
  Auth0::MissingUserId
93
128
  )
94
129
  end
95
130
  end
96
131
 
97
132
  context '.delete_user_provider' do
98
- it { expect(@instance).to respond_to(:delete_user_provider) }
99
- it 'is expected to call delete to /api/v2/users/userId/multifactor/provider' do
100
- expect(@instance).to receive(:delete).with('/api/v2/users/userId/multifactor/provider')
101
- @instance.delete_user_provider('userId', 'provider')
133
+ it 'is expected to respond to a delete_user_provider method' do
134
+ expect(@instance).to respond_to(:delete_user_provider)
135
+ end
136
+
137
+ it 'is expected to delete /api/v2/users/userId/multifactor/provider' do
138
+ expect(@instance).to receive(:delete).with('/api/v2/users/USER_ID/multifactor/PROVIDER_NAME')
139
+ @instance.delete_user_provider('USER_ID', 'PROVIDER_NAME')
140
+ end
141
+
142
+ it 'is expected to raise an exception when the user ID is empty' do
143
+ expect { @instance.delete_user_provider(nil, 'PROVIDER_NAME') }.to raise_exception(Auth0::MissingUserId)
144
+ end
145
+
146
+ it 'is expected to raise an exception when the provider name is empty' do
147
+ expect { @instance.delete_user_provider('USER_ID', nil) }.to raise_error 'Must supply a valid provider name'
102
148
  end
103
149
  end
104
150
 
105
151
  context '.patch_user' do
106
- it { expect(@instance).to respond_to(:patch_user) }
107
- it 'is expected to call patch to /api/v2/users/userID' do
152
+ it 'is expected to respond to a patch_user method' do
153
+ expect(@instance).to respond_to(:patch_user)
154
+ end
155
+
156
+ it 'is expected to respond to a update_user method' do
157
+ expect(@instance).to respond_to(:update_user)
158
+ end
159
+
160
+ it 'is expected to patch /api/v2/users/USER_ID' do
108
161
  expect(@instance).to receive(:patch).with(
109
- '/api/v2/users/UserID',
162
+ '/api/v2/users/USER_ID',
110
163
  email: 'test@test.com',
111
164
  password: 'password',
112
165
  connection: 'conn',
113
166
  name: 'name'
114
167
  )
115
168
  @instance.patch_user(
116
- 'UserID',
169
+ 'USER_ID',
117
170
  email: 'test@test.com',
118
171
  password: 'password',
119
172
  connection: 'conn',
120
173
  name: 'name'
121
174
  )
122
175
  end
123
- it { expect { @instance.patch_user('', 'body') }.to raise_error 'Must supply a valid user_id' }
124
- it { expect { @instance.patch_user('UserId', '') }.to raise_error 'Must supply a valid body' }
176
+
177
+ it 'is expected to raise an exception when the user ID is empty' do
178
+ expect { @instance.patch_user(nil, 'BODY') }.to raise_exception(Auth0::MissingUserId)
179
+ end
180
+
181
+ it 'is expected to raise an error when the body is empty' do
182
+ expect { @instance.patch_user('USER_ID', nil) }.to raise_error 'Must supply a valid body'
183
+ end
125
184
  end
126
185
 
127
186
  context '.link_user_account' do
128
- it { expect(@instance).to respond_to(:link_user_account) }
129
- it 'is expected to call post to /api/v2/users/UserId/identities' do
130
- expect(@instance).to receive(:post).with('/api/v2/users/UserID/identities', body: 'json body')
131
- @instance.link_user_account('UserID', body: 'json body')
187
+ it 'is expected to respond to a link_user_account method' do
188
+ expect(@instance).to respond_to(:link_user_account)
132
189
  end
133
- it { expect { @instance.link_user_account('', 'body') }.to raise_error 'Must supply a valid user_id' }
134
- it { expect { @instance.link_user_account('UserId', '') }.to raise_error 'Must supply a valid body' }
135
- end
136
190
 
137
- context '.unlink_users_account' do
138
- it { expect(@instance).to respond_to(:unlink_users_account) }
139
- it 'is expected to call delete to /api/v2/users/UserId/identities' do
140
- expect(@instance).to receive(:delete).with('/api/v2/users/UserID/identities/provider_name/Secondary_User_ID')
141
- @instance.unlink_users_account('UserID', 'provider_name', 'Secondary_User_ID')
191
+ it 'is expected to post to /api/v2/users/UserId/identities' do
192
+ expect(@instance).to receive(:post).with('/api/v2/users/USER_ID/identities', body: 'json body')
193
+ @instance.link_user_account('USER_ID', body: 'json body')
142
194
  end
143
- it { expect { @instance.unlink_users_account('', 'pro', 'SUserID') }.to raise_error 'Must supply a valid user_id' }
144
- it { expect { @instance.unlink_users_account('UID', nil, 'SUID') }.to raise_error 'Must supply a valid provider' }
145
- it do
146
- expect { @instance.unlink_users_account('UID', 'pro', nil) }.to raise_error 'Must supply a valid secondary user_id'
195
+
196
+ it 'is expected to raise an exception when the user ID is empty' do
197
+ expect { @instance.link_user_account(nil, 'BODY') }.to raise_exception(Auth0::MissingUserId)
198
+ end
199
+
200
+ it 'is expected to raise an error when the body is empty' do
201
+ expect { @instance.link_user_account('USER_ID', nil) }.to raise_error 'Must supply a valid body'
147
202
  end
148
203
  end
149
204
 
150
- context '.delete_user_provider' do
151
- it { expect(@instance).to respond_to(:delete_user_provider) }
152
- it 'is expected to call delete to /api/v2/users/User_ID/multifactor/provider_name' do
153
- expect(@instance).to receive(:delete).with('/api/v2/users/User_ID/multifactor/provider_name')
154
- @instance.delete_user_provider('User_ID', 'provider_name')
205
+ context '.unlink_user_account' do
206
+ it 'is expected to respond to a unlink_user_account method' do
207
+ expect(@instance).to respond_to(:unlink_user_account)
208
+ end
209
+ it 'is expected to respond to a unlink_users_account alias' do
210
+ expect(@instance).to respond_to(:unlink_users_account)
211
+ end
212
+
213
+ it 'is expected to delete /api/v2/users/UserId/identities' do
214
+ expect(@instance).to receive(:delete).with('/api/v2/users/USER_ID_1/identities/PROVIDER_NAME/USER_ID_2')
215
+ @instance.unlink_users_account('USER_ID_1', 'PROVIDER_NAME', 'USER_ID_2')
216
+ end
217
+
218
+ it 'is expected to raise an exception when the user ID is empty' do
219
+ expect do
220
+ @instance.unlink_users_account(nil, 'PROVIDER_NAME', 'USER_ID_2')
221
+ end.to raise_error 'Must supply a valid user_id'
222
+ end
223
+
224
+ it 'is expected to raise an exception when the provider is empty' do
225
+ expect do
226
+ @instance.unlink_users_account('USER_ID_1', nil, 'USER_ID_2')
227
+ end.to raise_error 'Must supply a valid provider'
228
+ end
229
+
230
+ it 'is expected to raise an exception when the secondary user ID is empty' do
231
+ expect do
232
+ @instance.unlink_users_account('USER_ID_1', 'PROVIDER_NAME', nil)
233
+ end.to raise_error 'Must supply a valid secondary user_id'
155
234
  end
156
- it { expect { @instance.delete_user_provider(nil, 'test') }.to raise_error 'Must supply a valid user_id' }
157
235
  end
158
236
 
159
237
  context '.user_logs' do
160
- it { expect(@instance).to respond_to(:user_logs) }
161
- it { expect(@instance).to respond_to(:get_user_log_events) }
162
- it 'is expected to call /api/v2/USER_ID/logs' do
238
+ it 'is expected to respond to a user_logs method' do
239
+ expect(@instance).to respond_to(:user_logs)
240
+ end
241
+
242
+ it 'is expected to respond to a get_user_log_events method' do
243
+ expect(@instance).to respond_to(:get_user_log_events)
244
+ end
245
+
246
+ it 'is expected to get /api/v2/USER_ID/logs' do
163
247
  expect(@instance).to receive(:get).with(
164
248
  '/api/v2/users/USER_ID/logs',
165
- user_id: 'USER_ID',
166
249
  per_page: nil,
167
250
  page: nil,
168
251
  include_totals: nil,
@@ -170,16 +253,273 @@ describe Auth0::Api::V2::Users do
170
253
  )
171
254
  expect { @instance.user_logs('USER_ID') }.not_to raise_error
172
255
  end
173
- it { expect { @instance.user_logs('') }.to raise_error 'Must supply a valid user_id' }
256
+
257
+ it 'is expected to raise an exception when the user ID is empty' do
258
+ expect { @instance.user_logs(nil) }.to raise_exception(Auth0::MissingUserId)
259
+ end
260
+
174
261
  it 'is expected to raise an error when per_page is higher than 100' do
175
262
  expect { @instance.user_logs('USER_ID', per_page: rand(101..2000)) }.to raise_error(
176
263
  'The total amount of entries per page should be less than 100'
177
264
  )
178
265
  end
266
+
179
267
  it 'is expected to raise an error when sort does not match pattern' do
180
268
  expect { @instance.user_logs('USER_ID', sort: 'no match') }.to raise_error(
181
269
  'Sort does not match pattern ^(([a-zA-Z0-9_\\.]+))\\:(1|-1)$'
182
270
  )
183
271
  end
184
272
  end
273
+
274
+ context '.get_roles' do
275
+ it 'is expected to respond to a get_roles method' do
276
+ expect(@instance).to respond_to(:get_user_roles)
277
+ end
278
+
279
+ it 'is expected to raise an exception when the user ID is empty' do
280
+ expect { @instance.get_user_roles(nil) }.to raise_exception(Auth0::MissingUserId)
281
+ end
282
+
283
+ it 'is expected to get roles with default parameters' do
284
+ expect(@instance).to receive(:get).with(
285
+ '/api/v2/users/USER_ID/roles',
286
+ per_page: nil,
287
+ page: nil,
288
+ include_totals: nil
289
+ )
290
+ expect { @instance.get_user_roles('USER_ID') }.not_to raise_error
291
+ end
292
+
293
+ it 'is expected to get roles with custom parameters' do
294
+ expect(@instance).to receive(:get).with(
295
+ '/api/v2/users/USER_ID/roles',
296
+ per_page: 20,
297
+ page: 2,
298
+ include_totals: true
299
+ )
300
+ expect do
301
+ @instance.get_user_roles('USER_ID', per_page: 20, page: 2, include_totals: true)
302
+ end.not_to raise_error
303
+ end
304
+ end
305
+
306
+ context '.remove_user_roles' do
307
+ it 'is expected to respond to a remove_user_roles method' do
308
+ expect(@instance).to respond_to(:remove_user_roles)
309
+ end
310
+
311
+ it 'is expected to raise an exception when the user ID is empty' do
312
+ expect { @instance.remove_user_roles(nil, 'ROLES') }.to raise_exception(Auth0::MissingUserId)
313
+ end
314
+
315
+ it 'is expected to raise an exception when the roles are not an array' do
316
+ expect { @instance.remove_user_roles('USER_ID', 'ROLES') }.to raise_exception(Auth0::InvalidParameter)
317
+ end
318
+
319
+ it 'is expected to raise an exception when the roles are empty' do
320
+ expect { @instance.remove_user_roles('USER_ID', []) }.to raise_exception(Auth0::MissingParameter)
321
+ end
322
+
323
+ it 'is expected to raise an exception when the roles are empty' do
324
+ expect { @instance.remove_user_roles('USER_ID', [1, 2]) }.to raise_exception(Auth0::InvalidParameter)
325
+ end
326
+
327
+ it 'is expected to remove roles' do
328
+ expect(@instance).to receive(:delete_with_body).with(
329
+ '/api/v2/users/USER_ID/roles',
330
+ roles: %w[test-role-01 test-role-02]
331
+ )
332
+ expect do
333
+ @instance.remove_user_roles('USER_ID', %w[test-role-01 test-role-02])
334
+ end.not_to raise_error
335
+ end
336
+ end
337
+
338
+ context '.add_roles' do
339
+ it 'is expected to respond to a add_roles method' do
340
+ expect(@instance).to respond_to(:add_user_roles)
341
+ end
342
+
343
+ it 'is expected to raise an exception when the user ID is empty' do
344
+ expect { @instance.add_user_roles(nil, 'ROLES') }.to raise_exception(Auth0::MissingUserId)
345
+ end
346
+
347
+ it 'is expected to raise an exception when the user ID is empty' do
348
+ expect { @instance.add_user_roles('USER_ID', 'ROLES') }.to raise_exception(Auth0::InvalidParameter)
349
+ end
350
+
351
+ it 'is expected to raise an exception when the roles are empty' do
352
+ expect { @instance.add_user_roles('USER_ID', [3, 4]) }.to raise_exception(Auth0::InvalidParameter)
353
+ end
354
+
355
+ it 'is expected to add roles' do
356
+ expect(@instance).to receive(:post).with(
357
+ '/api/v2/users/USER_ID/roles',
358
+ roles: %w[test-role-03 test-role-04]
359
+ )
360
+ expect do
361
+ @instance.add_user_roles('USER_ID', %w[test-role-03 test-role-04])
362
+ end.not_to raise_error
363
+ end
364
+ end
365
+
366
+ context '.get_enrollments' do
367
+ it 'is expected to respond to a get_enrollments method' do
368
+ expect(@instance).to respond_to(:get_enrollments)
369
+ end
370
+
371
+ it 'is expected to raise an exception when the user ID is empty' do
372
+ expect { @instance.get_enrollments(nil) }.to raise_exception(Auth0::MissingUserId)
373
+ end
374
+
375
+ it 'is expected to get enrollments' do
376
+ expect(@instance).to receive(:get).with('/api/v2/users/USER_ID/enrollments')
377
+ expect do
378
+ @instance.get_enrollments('USER_ID')
379
+ end.not_to raise_error
380
+ end
381
+ end
382
+
383
+ context '.get_permissions' do
384
+ it 'is expected to respond to a get_permissions method' do
385
+ expect(@instance).to respond_to(:get_user_permissions)
386
+ end
387
+
388
+ it 'is expected to raise an exception when the user ID is empty' do
389
+ expect { @instance.get_user_permissions(nil) }.to raise_exception(Auth0::MissingUserId)
390
+ end
391
+
392
+ it 'is expected to get permissions' do
393
+ expect(@instance).to receive(:get).with('/api/v2/users/USER_ID/permissions')
394
+ expect do
395
+ @instance.get_user_permissions('USER_ID')
396
+ end.not_to raise_error
397
+ end
398
+ end
399
+
400
+ context '.remove_permissions' do
401
+ it 'is expected to respond to a remove_permissions method' do
402
+ expect(@instance).to respond_to(:remove_user_permissions)
403
+ end
404
+
405
+ it 'is expected to raise an exception when the user ID is empty' do
406
+ expect { @instance.remove_user_permissions(nil, 'PERMISSIONS') }.to raise_exception(Auth0::MissingUserId)
407
+ end
408
+
409
+ it 'is expected to raise an exception when the permissions are empty' do
410
+ expect { @instance.remove_user_permissions('USER_ID', []) }.to raise_exception(Auth0::MissingParameter)
411
+ end
412
+
413
+ it 'is expected to raise an exception when the array does not consist of Permissions' do
414
+ expect do
415
+ @instance.remove_user_permissions('USER_ID', %w[permission-01 permission02])
416
+ end.to raise_exception(Auth0::InvalidParameter)
417
+ end
418
+
419
+ it 'is expected to remove permissions' do
420
+ expect(@instance).to receive(:delete_with_body).with(
421
+ '/api/v2/users/USER_ID/permissions',
422
+ permissions: [
423
+ {
424
+ permission_name: 'permission-name-1',
425
+ resource_server_identifier: 'server-id-1'
426
+ },
427
+ {
428
+ permission_name: 'permission-name-2',
429
+ resource_server_identifier: 'server-id-2'
430
+ }
431
+ ]
432
+ )
433
+ expect do
434
+ @instance.remove_user_permissions(
435
+ 'USER_ID',
436
+ [
437
+ Permission.new('permission-name-1', 'server-id-1'),
438
+ Permission.new('permission-name-2', 'server-id-2')
439
+ ]
440
+ )
441
+ end.not_to raise_error
442
+ end
443
+ end
444
+
445
+ context '.add_permissions' do
446
+ it 'is expected to respond to a add_permissions method' do
447
+ expect(@instance).to respond_to(:add_user_permissions)
448
+ end
449
+
450
+ it 'is expected to raise an exception when the user ID is empty' do
451
+ expect { @instance.add_user_permissions(nil, 'PERMISSIONS') }.to raise_exception(Auth0::MissingUserId)
452
+ end
453
+
454
+ it 'is expected to raise an exception when the permissions are empty' do
455
+ expect { @instance.add_user_permissions('USER_ID', []) }.to raise_exception(Auth0::MissingParameter)
456
+ end
457
+
458
+ it 'is expected to raise an exception when the permissions are not Permission structs' do
459
+ expect do
460
+ @instance.add_user_permissions('USER_ID', %w[permission-01 permission02])
461
+ end.to raise_exception(Auth0::InvalidParameter)
462
+ end
463
+
464
+ it 'is expected to add permissions' do
465
+ expect(@instance).to receive(:post).with(
466
+ '/api/v2/users/USER_ID/permissions',
467
+ permissions: [
468
+ {
469
+ permission_name: 'permission-name-1',
470
+ resource_server_identifier: 'server-id-1'
471
+ },
472
+ {
473
+ permission_name: 'permission-name-2',
474
+ resource_server_identifier: 'server-id-2'
475
+ }
476
+ ]
477
+ )
478
+ expect do
479
+ @instance.add_user_permissions(
480
+ 'USER_ID',
481
+ [
482
+ Permission.new('permission-name-1', 'server-id-1'),
483
+ Permission.new('permission-name-2', 'server-id-2')
484
+ ]
485
+ )
486
+ end.not_to raise_error
487
+ end
488
+ end
489
+
490
+ context '.generate_recovery_code' do
491
+ it 'is expected to respond to a generate_recovery_code method' do
492
+ expect(@instance).to respond_to(:generate_recovery_code)
493
+ end
494
+
495
+ it 'is expected to raise an exception when the user ID is empty' do
496
+ expect { @instance.generate_recovery_code(nil) }.to raise_exception(Auth0::MissingUserId)
497
+ end
498
+
499
+ it 'is expected to get generate a recovery code' do
500
+ expect(@instance).to receive(:post).with('/api/v2/users/USER_ID/recovery-code-generation')
501
+ expect do
502
+ @instance.generate_recovery_code('USER_ID')
503
+ end.not_to raise_error
504
+ end
505
+ end
506
+
507
+ context '.invalidate_browsers' do
508
+ it 'is expected to respond to a invalidate_browsers method' do
509
+ expect(@instance).to respond_to(:invalidate_browsers)
510
+ end
511
+
512
+ it 'is expected to raise an exception when the user ID is empty' do
513
+ expect { @instance.invalidate_browsers(nil) }.to raise_exception(Auth0::MissingUserId)
514
+ end
515
+
516
+ it 'is expected to invalidate remembered browsers' do
517
+ expect(@instance).to receive(:post).with(
518
+ '/api/v2/users/USER_ID/multifactor/actions/invalidate-remember-browser'
519
+ )
520
+ expect do
521
+ @instance.invalidate_browsers('USER_ID')
522
+ end.not_to raise_error
523
+ end
524
+ end
185
525
  end