auth0 4.7.0 → 4.12.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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -0
  3. data/.env.example +2 -0
  4. data/.github/CODEOWNERS +1 -0
  5. data/.github/stale.yml +20 -0
  6. data/.gitignore +0 -1
  7. data/.rubocop.yml +2 -0
  8. data/CHANGELOG.md +83 -0
  9. data/DEPLOYMENT.md +25 -3
  10. data/Gemfile +3 -1
  11. data/Gemfile.lock +231 -0
  12. data/README.md +114 -25
  13. data/auth0.gemspec +6 -6
  14. data/codecov.yml +22 -0
  15. data/deploy_documentation.sh +1 -1
  16. data/lib/auth0.rb +1 -0
  17. data/lib/auth0/algorithm.rb +5 -0
  18. data/lib/auth0/api/authentication_endpoints.rb +38 -2
  19. data/lib/auth0/api/v2.rb +6 -0
  20. data/lib/auth0/api/v2/anomaly.rb +36 -0
  21. data/lib/auth0/api/v2/client_grants.rb +5 -1
  22. data/lib/auth0/api/v2/guardian.rb +142 -0
  23. data/lib/auth0/api/v2/jobs.rb +22 -3
  24. data/lib/auth0/api/v2/roles.rb +172 -0
  25. data/lib/auth0/api/v2/users.rb +115 -4
  26. data/lib/auth0/exception.rb +35 -7
  27. data/lib/auth0/mixins.rb +8 -3
  28. data/lib/auth0/mixins/httpproxy.rb +11 -8
  29. data/lib/auth0/mixins/permission_struct.rb +3 -0
  30. data/lib/auth0/mixins/validation.rb +340 -0
  31. data/lib/auth0/version.rb +1 -1
  32. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_check_if_ip_is_blocked/should_return_200_response_code.yml +65 -0
  33. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_remove_ip_block/should_remove_an_IP_successfully.yml +60 -0
  34. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_at_least_1_result.yml +1 -1
  35. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_first_page_of_one_result.yml +1 -1
  36. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_test_client_grant.yml +1 -1
  37. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_delete_client_grant/should_delete_the_test_client_grant.yml +1 -1
  38. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_patch_client_grant/should_update_the_test_client_grant.yml +1 -1
  39. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client.yml +1 -1
  40. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client_grant.yml +1 -1
  41. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client.yml +1 -1
  42. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client_grant.yml +1 -1
  43. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_exclude_and_include_fields_properly.yml +1 -1
  44. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_include_the_specified_fields.yml +1 -1
  45. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/should_get_the_test_client.yml +1 -1
  46. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_fields_not_specified.yml +1 -1
  47. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_the_specified_fields.yml +1 -1
  48. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_include_the_specified_fields.yml +1 -1
  49. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_paginate_results.yml +1 -1
  50. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/should_get_at_least_one_client.yml +1 -1
  51. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_delete_client/should_delete_the_test_client_without_an_error.yml +1 -1
  52. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +1 -1
  53. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/create_test_client.yml +1 -1
  54. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_exclude_the_fields_indicated.yml +1 -1
  55. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_include_the_fields_indicated.yml +1 -1
  56. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/should_find_the_correct_connection.yml +1 -1
  57. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_include_previously-created_connection_when_filtered.yml +1 -1
  58. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_exclude_the_fields_indicated_from_filtered_results.yml +1 -1
  59. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_include_the_fields_indicated_from_filtered_results.yml +1 -1
  60. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_include_the_previously_created_connection.yml +1 -1
  61. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_not_be_empty.yml +1 -1
  62. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection/should_delete_the_connection.yml +1 -1
  63. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection_user/should_delete_the_user_created.yml +2 -2
  64. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +1 -1
  65. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_connection.yml +1 -1
  66. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_user.yml +1 -1
  67. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_user.yml +1 -1
  68. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_credential.yml +1 -1
  69. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_user.yml +1 -1
  70. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_configure_provider/should_configure_a_new_email_provider.yml +1 -1
  71. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_delete_the_existing_email_provider_without_an_error.yml +1 -1
  72. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_throw_an_error_trying_to_get_the_email_provider.yml +1 -1
  73. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_with_specific_fields.yml +1 -1
  74. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_without_specific_fields.yml +1 -1
  75. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/should_get_the_existing_email_provider.yml +1 -1
  76. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_update_provider/should_update_the_existing_email_provider.yml +1 -1
  77. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/delete_existing_provider.yml +1 -1
  78. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_match_the_created_log_entry.yml +2 -2
  79. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_not_be_empty.yml +2 -2
  80. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_fields_not_specified.yml +1 -1
  81. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_the_specified_fields.yml +1 -1
  82. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_have_one_log_entry.yml +1 -1
  83. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_include_the_specified_fields.yml +1 -1
  84. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_from/should_take_one_log_entry.yml +2 -2
  85. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/create_test_user.yml +1 -1
  86. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_disabled_rule.yml +1 -1
  87. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_enabled_rule.yml +1 -1
  88. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_user.yml +1 -1
  89. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_permissions/should_add_a_Permission_to_the_Role_successfully.yml +69 -0
  90. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_users/should_add_a_User_to_the_Role_successfully.yml +69 -0
  91. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_delete_role/should_delete_the_Role_successfully.yml +62 -0
  92. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role/should_get_the_Role_successfully.yml +67 -0
  93. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_exactly_1_Permission.yml +67 -0
  94. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_the_added_Permission_from_the_Role_successfully.yml +67 -0
  95. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_exactly_1_User.yml +67 -0
  96. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_the_added_User_from_the_Role_successfully.yml +67 -0
  97. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_roles/should_get_the_Role_successfully.yml +67 -0
  98. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_remove_role_permissions/should_remove_a_Permission_from_the_Role_successfully.yml +64 -0
  99. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_update_role/should_update_the_Role_successfully.yml +69 -0
  100. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_api.yml +69 -0
  101. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_role.yml +69 -0
  102. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_user.yml +69 -0
  103. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_api.yml +62 -0
  104. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_user.yml +62 -0
  105. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_disabled_rule_without_an_error.yml +1 -1
  106. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_enabled_rule_without_an_error.yml +1 -1
  107. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_fields_not_specified.yml +1 -1
  108. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_specified_fields.yml +1 -1
  109. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_include_the_specified_fields.yml +1 -1
  110. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/should_get_a_specific_rule.yml +1 -1
  111. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_exclude_fields_not_specified.yml +1 -1
  112. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_include_the_specified_fields.yml +1 -1
  113. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_disabled_rule.yml +1 -1
  114. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_enabled_rule.yml +1 -1
  115. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_paginated_results.yml +2 -2
  116. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/should_return_at_least_1_rule.yml +1 -1
  117. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +1 -1
  118. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_disabled_rule.yml +1 -1
  119. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_enabled_rule.yml +1 -1
  120. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_active_users/should_have_at_least_one_active_user.yml +1 -1
  121. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_daily_stats/should_have_at_least_one_stats_entry_for_the_timeframe.yml +1 -1
  122. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings/should_get_the_tenant_settings.yml +1 -1
  123. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_exclude_a_field_not_requested.yml +1 -1
  124. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_include_the_field_requested.yml +1 -1
  125. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +1 -1
  126. 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
  127. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_email_verification/should_create_an_email_verification_ticket.yml +1 -1
  128. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_password_change/should_create_a_password_change_ticket.yml +1 -1
  129. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/create_test_user.yml +1 -1
  130. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/delete_test_user.yml +1 -1
  131. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_permissions/should_add_a_Permissions_for_a_User_successfully.yml +67 -0
  132. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +62 -0
  133. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/{should_delete_the_user_successfully.yml → should_delete_the_User_successfully.yml} +14 -8
  134. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_secondary_User_successfully.yml +60 -0
  135. 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
  136. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_enrollments/should_get_Enrollments_for_a_User_successfully.yml +65 -0
  137. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_exactly_1_Permission_for_a_User_successfully.yml +65 -0
  138. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_the_correct_Permission_for_a_User_successfully.yml +65 -0
  139. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_roles/should_get_Roles_for_a_User_successfully.yml +65 -0
  140. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_invalidate_browsers/should_invalidate_MFA_browsers_for_the_User_successfully.yml +62 -0
  141. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_link_user_account/should_link_two_Users_successfully.yml +67 -0
  142. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +68 -0
  143. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_permissions/should_remove_a_Permission_from_a_User_successfully.yml +62 -0
  144. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_roles/should_remove_a_Role_from_a_User_successfully.yml +62 -0
  145. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_unlink_user_account/should_unlink_two_Users_successfully.yml +65 -0
  146. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_fields_not_indicated.yml +15 -10
  147. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_the_fields_indicated.yml +15 -13
  148. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_include_the_fields_indicated.yml +15 -13
  149. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/should_retrieve_the_created_user.yml +15 -16
  150. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user_logs/should_get_Logs_for_a_User_successfully.yml +69 -0
  151. 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
  152. 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
  153. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_exclude_the_indicated_fields_when_paginated.yml +13 -7
  154. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_include_the_indicated_fields_when_paginated.yml +13 -7
  155. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_not_include_other_fields_when_paginated.yml +13 -7
  156. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_return_the_correct_number_of_results_when_paginated.yml +13 -7
  157. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/should_have_at_least_one_user.yml +13 -7
  158. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_secondary_test_user.yml +67 -0
  159. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_api.yml +67 -0
  160. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_role.yml +67 -0
  161. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_user.yml +15 -16
  162. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_api.yml +60 -0
  163. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_role.yml +60 -0
  164. data/spec/integration/lib/auth0/api/v2/api_anomaly_spec.rb +17 -0
  165. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +145 -0
  166. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +150 -32
  167. data/spec/integration/lib/auth0/auth0_client_spec.rb +3 -4
  168. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +37 -10
  169. data/spec/lib/auth0/api/v2/anomaly_spec.rb +26 -0
  170. data/spec/lib/auth0/api/v2/client_grants_spec.rb +17 -0
  171. data/spec/lib/auth0/api/v2/guardian_spec.rb +154 -0
  172. data/spec/lib/auth0/api/v2/jobs_spec.rb +33 -1
  173. data/spec/lib/auth0/api/v2/roles_spec.rb +362 -0
  174. data/spec/lib/auth0/api/v2/users_spec.rb +406 -66
  175. data/spec/lib/auth0/mixins/httpproxy_spec.rb +81 -2
  176. data/spec/lib/auth0/mixins/validation_spec.rb +474 -0
  177. data/spec/spec_helper.rb +11 -7
  178. data/spec/support/credentials.rb +4 -13
  179. data/spec/support/dummy_class.rb +1 -1
  180. data/spec/support/stub_response.rb +1 -1
  181. metadata +145 -23
  182. data/.travis.yml +0 -18
  183. data/build_travis.sh +0 -7
  184. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_email_verified_and_return_the_updated_data.yml +0 -68
  185. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_user_metadata_and_return_the_updated_user.yml +0 -69
@@ -13,14 +13,46 @@ describe Auth0::Api::V2::Jobs do
13
13
  end
14
14
  it { expect { @instance.get_job('') }.to raise_error('Must specify a job id') }
15
15
  end
16
+ context '.get_job_errors' do
17
+ it { expect(@instance).to respond_to(:get_job_errors) }
18
+ it 'expect client to send get to /api/v2/jobs/3/errors' do
19
+ expect(@instance).to receive(:get).with('/api/v2/jobs/3/errors')
20
+ expect { @instance.get_job_errors(3) }.not_to raise_error
21
+ end
22
+ it { expect { @instance.get_job_errors('') }.to raise_error('Must specify a job id') }
23
+ end
16
24
  context '.import_users' do
17
25
  it { expect(@instance).to respond_to(:import_users) }
18
26
  it 'expect client to send post to /api/v2/jobs/users-imports' do
19
27
  expect(@instance).to receive(:post_file).with(
20
- '/api/v2/jobs/users-imports', users: 'file', connection_id: 'connnection_id'
28
+ '/api/v2/jobs/users-imports',
29
+ users: 'file',
30
+ connection_id: 'connnection_id',
31
+ upsert: false,
32
+ external_id: nil,
33
+ send_completion_email: true
21
34
  )
22
35
  expect { @instance.import_users('file', 'connnection_id') }.not_to raise_error
23
36
  end
37
+ it 'expect client to send post to /api/v2/jobs/users-imports with options' do
38
+ expect(@instance).to receive(:post_file).with(
39
+ '/api/v2/jobs/users-imports',
40
+ users: 'file',
41
+ connection_id: 'connnection_id',
42
+ upsert: true,
43
+ external_id: 'external_1',
44
+ send_completion_email: false
45
+ )
46
+ expect do
47
+ @instance.import_users(
48
+ 'file',
49
+ 'connnection_id',
50
+ upsert: true,
51
+ external_id: 'external_1',
52
+ send_completion_email: false
53
+ )
54
+ end.not_to raise_error
55
+ end
24
56
  it { expect { @instance.import_users('', 'connnection_id') }.to raise_error('Must specify a valid file') }
25
57
  it { expect { @instance.import_users('users', '') }.to raise_error('Must specify a connection_id') }
26
58
  end
@@ -0,0 +1,362 @@
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
+ name_filter: nil
25
+ )
26
+ expect { @instance.get_roles }.not_to raise_error
27
+ end
28
+
29
+ it 'is expected to get Roles with custom parameters' do
30
+ expect(@instance).to receive(:get).with(
31
+ '/api/v2/roles',
32
+ per_page: 10,
33
+ page: 3,
34
+ include_totals: true,
35
+ name_filter: 'test'
36
+ )
37
+ expect do
38
+ @instance.get_roles(per_page: 10, page: 3, include_totals: true, name_filter: 'test')
39
+ end.not_to raise_error
40
+ end
41
+ end
42
+
43
+ context '.get_role' do
44
+ it 'is expected to exist' do
45
+ expect(@instance).to respond_to(:get_role)
46
+ end
47
+
48
+ it 'is expected to have a role alias' do
49
+ expect(@instance).to respond_to(:role)
50
+ end
51
+
52
+ it 'is expected to raise an exception if an empty Role ID is passed' do
53
+ expect(@instance).not_to receive(:get)
54
+ expect do
55
+ @instance.get_role('')
56
+ end.to raise_exception Auth0::MissingParameter
57
+ end
58
+
59
+ it 'is expected to get a Role by ID' do
60
+ expect(@instance).to receive(:get).with('/api/v2/roles/ROLE_ID')
61
+ expect { @instance.get_role('ROLE_ID') }.not_to raise_error
62
+ end
63
+ end
64
+
65
+ context '.create_role' do
66
+ it 'is expected to exist' do
67
+ expect(@instance).to respond_to(:create_role)
68
+ end
69
+
70
+ it 'is expected to raise an exception if an empty Role name is passed' do
71
+ expect(@instance).not_to receive(:post)
72
+ expect do
73
+ @instance.create_role('')
74
+ end.to raise_exception Auth0::MissingParameter
75
+ end
76
+
77
+ it 'is expected to post a new Role' do
78
+ expect(@instance).to receive(:post).with(
79
+ '/api/v2/roles',
80
+ name: 'ROLE_NAME',
81
+ description: 'ROLE_DESCRIPTION'
82
+ )
83
+ expect do
84
+ @instance.create_role(
85
+ 'ROLE_NAME',
86
+ description: 'ROLE_DESCRIPTION'
87
+ )
88
+ end.not_to raise_error
89
+ end
90
+ end
91
+
92
+ context '.update_role' do
93
+ it 'is expected to exist' do
94
+ expect(@instance).to respond_to(:update_role)
95
+ end
96
+
97
+ it 'is expected to raise an exception if an empty Role ID is passed' do
98
+ expect(@instance).not_to receive(:patch)
99
+ expect do
100
+ @instance.update_role('')
101
+ end.to raise_exception Auth0::MissingParameter
102
+ end
103
+
104
+ it 'is expected to post an updated Role' do
105
+ expect(@instance).to receive(:patch).with(
106
+ '/api/v2/roles/ROLE_ID',
107
+ name: 'ROLE_NAME',
108
+ description: 'ROLE_DESCRIPTION'
109
+ )
110
+ expect do
111
+ @instance.update_role(
112
+ 'ROLE_ID',
113
+ name: 'ROLE_NAME',
114
+ description: 'ROLE_DESCRIPTION'
115
+ )
116
+ end.not_to raise_error
117
+ end
118
+ end
119
+
120
+ context '.delete_role' do
121
+ it 'is expected to exist' do
122
+ expect(@instance).to respond_to(:delete_role)
123
+ end
124
+
125
+ it 'is expected to raise an exception if an empty Role ID is passed' do
126
+ expect(@instance).not_to receive(:delete)
127
+ expect do
128
+ @instance.delete_role('')
129
+ end.to raise_exception Auth0::MissingParameter
130
+ end
131
+
132
+ it 'is expected to delete a Role' do
133
+ expect(@instance).to receive(:delete).with('/api/v2/roles/ROLE_ID')
134
+ expect { @instance.delete_role('ROLE_ID') }.not_to raise_error
135
+ end
136
+ end
137
+
138
+ context '.get_users' do
139
+ it 'is expected to exist' do
140
+ expect(@instance).to respond_to(:get_role_users)
141
+ end
142
+
143
+ it 'is expected to raise an exception if an empty Role ID is passed' do
144
+ expect(@instance).not_to receive(:get)
145
+ expect do
146
+ @instance.get_role_users('')
147
+ end.to raise_exception Auth0::MissingParameter
148
+ end
149
+
150
+ it 'is expected to get Users for a Role with default parameters' do
151
+ expect(@instance).to receive(:get).with(
152
+ '/api/v2/roles/ROLE_ID/users',
153
+ per_page: nil,
154
+ page: nil,
155
+ include_totals: nil
156
+ )
157
+ expect { @instance.get_role_users('ROLE_ID') }.not_to raise_error
158
+ end
159
+
160
+ it 'is expected to get Users for a Role with custom parameters' do
161
+ expect(@instance).to receive(:get).with(
162
+ '/api/v2/roles/ROLE_ID/users',
163
+ per_page: 30,
164
+ page: 4,
165
+ include_totals: true
166
+ )
167
+ expect do
168
+ @instance.get_role_users('ROLE_ID', per_page: 30, page: 4, include_totals: true)
169
+ end.not_to raise_error
170
+ end
171
+ end
172
+
173
+ context '.add_users' do
174
+ it 'is expected to exist' do
175
+ expect(@instance).to respond_to(:add_role_users)
176
+ end
177
+
178
+ it 'is expected to raise an exception if an empty Role ID is passed' do
179
+ expect(@instance).not_to receive(:post)
180
+ expect do
181
+ @instance.add_role_users('', [])
182
+ end.to raise_exception Auth0::MissingParameter
183
+ end
184
+
185
+ it 'is expected to raise an exception if an array is not passed for Users' do
186
+ expect(@instance).not_to receive(:post)
187
+ expect do
188
+ @instance.add_role_users('ROLE_ID', 'USERS')
189
+ end.to raise_exception Auth0::InvalidParameter
190
+ end
191
+
192
+ it 'is expected to raise an exception if no User IDs are passed' do
193
+ expect(@instance).not_to receive(:post)
194
+ expect do
195
+ @instance.add_role_users('ROLE_ID', [])
196
+ end.to raise_exception Auth0::MissingParameter
197
+ end
198
+
199
+ it 'is expected to add Users to a Role' do
200
+ expect(@instance).to receive(:post).with(
201
+ '/api/v2/roles/ROLE_ID/users',
202
+ users: %w[test|user-01 test|user-02]
203
+ )
204
+ expect do
205
+ @instance.add_role_users('ROLE_ID', %w[test|user-01 test|user-02])
206
+ end.not_to raise_error
207
+ end
208
+ end
209
+
210
+ context '.get_permissions' do
211
+ it 'is expected to exist' do
212
+ expect(@instance).to respond_to(:get_role_permissions)
213
+ end
214
+
215
+ it 'is expected to raise an exception if an empty Role ID is passed' do
216
+ expect(@instance).not_to receive(:get)
217
+ expect do
218
+ @instance.get_role_permissions('')
219
+ end.to raise_exception Auth0::MissingParameter
220
+ end
221
+
222
+ it 'is expected to get Roles with default parameters' do
223
+ expect(@instance).to receive(:get).with(
224
+ '/api/v2/roles/ROLE_ID/permissions',
225
+ per_page: nil,
226
+ page: nil,
227
+ include_totals: nil
228
+ )
229
+ expect { @instance.get_role_permissions('ROLE_ID') }.not_to raise_error
230
+ end
231
+
232
+ it 'is expected to get Roles with custom parameters' do
233
+ expect(@instance).to receive(:get).with(
234
+ '/api/v2/roles/ROLE_ID/permissions',
235
+ per_page: 15,
236
+ page: 5,
237
+ include_totals: true
238
+ )
239
+ expect do
240
+ @instance.get_role_permissions('ROLE_ID', per_page: 15, page: 5, include_totals: true)
241
+ end.not_to raise_error
242
+ end
243
+ end
244
+
245
+ context '.add_permissions' do
246
+ it 'is expected to exist' do
247
+ expect(@instance).to respond_to(:add_role_permissions)
248
+ end
249
+
250
+ it 'is expected to raise an exception if an empty Role ID is passed' do
251
+ expect(@instance).not_to receive(:post)
252
+ expect do
253
+ @instance.add_role_permissions('', [])
254
+ end.to raise_exception Auth0::MissingParameter
255
+ end
256
+
257
+ it 'is expected to raise an exception if an array is not passed for permissions' do
258
+ expect(@instance).not_to receive(:post)
259
+ expect do
260
+ @instance.add_role_permissions('ROLE_ID', 'PERMISSIONS')
261
+ end.to raise_exception Auth0::InvalidParameter
262
+ end
263
+
264
+ it 'is expected to raise an exception if an empty permissions array is passed' do
265
+ expect(@instance).not_to receive(:post)
266
+ expect do
267
+ @instance.add_role_permissions('ROLE_ID', [])
268
+ end.to raise_exception Auth0::MissingParameter
269
+ end
270
+
271
+ it 'is expected to raise an exception if the permissions array does not contain Permission structs' do
272
+ expect(@instance).not_to receive(:post)
273
+ expect do
274
+ @instance.add_role_permissions('ROLE_ID', [1, 2, 3])
275
+ end.to raise_exception Auth0::InvalidParameter
276
+ end
277
+
278
+ it 'is expected to add permissions to a Role' do
279
+ expect(@instance).to receive(:post).with(
280
+ '/api/v2/roles/ROLE_ID/permissions',
281
+ permissions: [
282
+ {
283
+ permission_name: 'permission-name-1',
284
+ resource_server_identifier: 'server-id-1'
285
+ },
286
+ {
287
+ permission_name: 'permission-name-2',
288
+ resource_server_identifier: 'server-id-2'
289
+ }
290
+ ]
291
+ )
292
+ expect do
293
+ @instance.add_role_permissions(
294
+ 'ROLE_ID',
295
+ [
296
+ Permission.new('permission-name-1', 'server-id-1'),
297
+ Permission.new('permission-name-2', 'server-id-2')
298
+ ]
299
+ )
300
+ end.not_to raise_error
301
+ end
302
+ end
303
+
304
+ context '.remove_permissions' do
305
+ it 'is expected to exist' do
306
+ expect(@instance).to respond_to(:remove_role_permissions)
307
+ end
308
+
309
+ it 'is expected to raise an exception if an empty Role ID is passed' do
310
+ expect(@instance).not_to receive(:delete_with_body)
311
+ expect do
312
+ @instance.remove_role_permissions('', [])
313
+ end.to raise_exception Auth0::MissingParameter
314
+ end
315
+
316
+ it 'is expected to raise an exception if an array is not passed for permissions' do
317
+ expect(@instance).not_to receive(:post)
318
+ expect do
319
+ @instance.remove_role_permissions('ROLE_ID', 'PERMISSIONS')
320
+ end.to raise_exception Auth0::InvalidParameter
321
+ end
322
+
323
+ it 'is expected to raise an exception if an empty permissions array is passed' do
324
+ expect(@instance).not_to receive(:delete_with_body)
325
+ expect do
326
+ @instance.remove_role_permissions('ROLE_ID', [])
327
+ end.to raise_exception Auth0::MissingParameter
328
+ end
329
+
330
+ it 'is expected to raise an exception if the permissions array does not contain Permission structs' do
331
+ expect(@instance).not_to receive(:post)
332
+ expect do
333
+ @instance.remove_role_permissions('ROLE_ID', [1, 2, 3])
334
+ end.to raise_exception Auth0::InvalidParameter
335
+ end
336
+
337
+ it 'is expected to remove permissions from a Role' do
338
+ expect(@instance).to receive(:delete_with_body).with(
339
+ '/api/v2/roles/ROLE_ID/permissions',
340
+ permissions: [
341
+ {
342
+ permission_name: 'permission-name-3',
343
+ resource_server_identifier: 'server-id-3'
344
+ },
345
+ {
346
+ permission_name: 'permission-name-4',
347
+ resource_server_identifier: 'server-id-4'
348
+ }
349
+ ]
350
+ )
351
+ expect do
352
+ @instance.remove_role_permissions(
353
+ 'ROLE_ID',
354
+ [
355
+ Permission.new('permission-name-3', 'server-id-3'),
356
+ Permission.new('permission-name-4', 'server-id-4')
357
+ ]
358
+ )
359
+ end.not_to raise_error
360
+ end
361
+ end
362
+ 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