workosv2 2.15.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.
- checksums.yaml +7 -0
- data/.github/CODEOWNERS +5 -0
- data/.github/pull_request_template.md +11 -0
- data/.github/renovate.json +5 -0
- data/.gitignore +49 -0
- data/.rspec +1 -0
- data/.rubocop.yml +24 -0
- data/.ruby-version +1 -0
- data/.semaphore/rubygems.yml +24 -0
- data/.semaphore/semaphore.yml +51 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +126 -0
- data/Gemfile.lock.old +127 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/bin/build +3 -0
- data/bin/console +3 -0
- data/bin/docs +5 -0
- data/bin/publish +3 -0
- data/bin/tapioca +29 -0
- data/codecov.yml +12 -0
- data/docs/WorkOS/APIError.html +160 -0
- data/docs/WorkOS/AuditLog.html +235 -0
- data/docs/WorkOS/AuditTrail.html +235 -0
- data/docs/WorkOS/AuthenticationError.html +160 -0
- data/docs/WorkOS/Base.html +287 -0
- data/docs/WorkOS/Client.html +504 -0
- data/docs/WorkOS/InvalidRequestError.html +160 -0
- data/docs/WorkOS/Profile.html +788 -0
- data/docs/WorkOS/RequestError.html +135 -0
- data/docs/WorkOS/SSO.html +691 -0
- data/docs/WorkOS/Types/ProfileStruct.html +135 -0
- data/docs/WorkOS/Types/Provider.html +135 -0
- data/docs/WorkOS/Types.html +128 -0
- data/docs/WorkOS/WorkOSError.html +447 -0
- data/docs/WorkOS.html +324 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.README.html +252 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +250 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +267 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/workosv2/audit_log_export.rb +55 -0
- data/lib/workosv2/audit_logs.rb +114 -0
- data/lib/workosv2/audit_trail.rb +111 -0
- data/lib/workosv2/challenge.rb +55 -0
- data/lib/workosv2/client.rb +186 -0
- data/lib/workosv2/configuration.rb +17 -0
- data/lib/workosv2/connection.rb +66 -0
- data/lib/workosv2/deprecated_hash_wrapper.rb +76 -0
- data/lib/workosv2/directory.rb +65 -0
- data/lib/workosv2/directory_group.rb +68 -0
- data/lib/workosv2/directory_sync.rb +218 -0
- data/lib/workosv2/directory_user.rb +97 -0
- data/lib/workosv2/errors.rb +81 -0
- data/lib/workosv2/event.rb +51 -0
- data/lib/workosv2/events.rb +52 -0
- data/lib/workosv2/factor.rb +54 -0
- data/lib/workosv2/hash_provider.rb +19 -0
- data/lib/workosv2/mfa.rb +178 -0
- data/lib/workosv2/organization.rb +57 -0
- data/lib/workosv2/organizations.rb +188 -0
- data/lib/workosv2/passwordless.rb +85 -0
- data/lib/workosv2/portal.rb +66 -0
- data/lib/workosv2/profile.rb +76 -0
- data/lib/workosv2/profile_and_token.rb +29 -0
- data/lib/workosv2/sso.rb +297 -0
- data/lib/workosv2/types/audit_log_export_struct.rb +17 -0
- data/lib/workosv2/types/challenge_struct.rb +18 -0
- data/lib/workosv2/types/connection_struct.rb +20 -0
- data/lib/workosv2/types/directory_group_struct.rb +19 -0
- data/lib/workosv2/types/directory_struct.rb +19 -0
- data/lib/workosv2/types/directory_user_struct.rb +26 -0
- data/lib/workosv2/types/event_struct.rb +15 -0
- data/lib/workosv2/types/factor_struct.rb +18 -0
- data/lib/workosv2/types/intent_enum.rb +17 -0
- data/lib/workosv2/types/list_struct.rb +13 -0
- data/lib/workosv2/types/organization_struct.rb +17 -0
- data/lib/workosv2/types/passwordless_session_struct.rb +17 -0
- data/lib/workosv2/types/profile_struct.rb +21 -0
- data/lib/workosv2/types/provider_enum.rb +15 -0
- data/lib/workosv2/types/verify_challenge_struct.rb +13 -0
- data/lib/workosv2/types/webhook_struct.rb +15 -0
- data/lib/workosv2/types.rb +25 -0
- data/lib/workosv2/verify_challenge.rb +39 -0
- data/lib/workosv2/version.rb +6 -0
- data/lib/workosv2/webhook.rb +51 -0
- data/lib/workosv2/webhooks.rb +217 -0
- data/lib/workosv2.rb +79 -0
- data/sorbet/config +2 -0
- data/sorbet/rbi/gems/addressable@2.8.0.rbi +290 -0
- data/sorbet/rbi/gems/ast@2.4.2.rbi +54 -0
- data/sorbet/rbi/gems/codecov@0.2.12.rbi +55 -0
- data/sorbet/rbi/gems/coderay@1.1.3.rbi +8 -0
- data/sorbet/rbi/gems/crack@0.4.5.rbi +57 -0
- data/sorbet/rbi/gems/diff-lcs@1.4.4.rbi +185 -0
- data/sorbet/rbi/gems/docile@1.3.5.rbi +54 -0
- data/sorbet/rbi/gems/hashdiff@1.0.1.rbi +82 -0
- data/sorbet/rbi/gems/json@2.5.1.rbi +109 -0
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +8 -0
- data/sorbet/rbi/gems/parallel@1.20.1.rbi +113 -0
- data/sorbet/rbi/gems/parser@3.0.1.0.rbi +1187 -0
- data/sorbet/rbi/gems/pry@0.14.2.rbi +8 -0
- data/sorbet/rbi/gems/public_suffix@4.0.6.rbi +146 -0
- data/sorbet/rbi/gems/rainbow@3.0.0.rbi +153 -0
- data/sorbet/rbi/gems/rake@13.0.3.rbi +807 -0
- data/sorbet/rbi/gems/rbi@0.0.16.rbi +2118 -0
- data/sorbet/rbi/gems/regexp_parser@2.1.1.rbi +1117 -0
- data/sorbet/rbi/gems/rexml@3.2.5.rbi +709 -0
- data/sorbet/rbi/gems/rspec-core@3.9.3.rbi +2467 -0
- data/sorbet/rbi/gems/rspec-expectations@3.9.4.rbi +1569 -0
- data/sorbet/rbi/gems/rspec-mocks@3.9.1.rbi +1493 -0
- data/sorbet/rbi/gems/rspec-support@3.9.4.rbi +511 -0
- data/sorbet/rbi/gems/rspec@3.9.0.rbi +38 -0
- data/sorbet/rbi/gems/rubocop-ast@1.4.1.rbi +1881 -0
- data/sorbet/rbi/gems/rubocop@0.93.1.rbi +11497 -0
- data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +405 -0
- data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +89 -0
- data/sorbet/rbi/gems/simplecov@0.21.2.rbi +577 -0
- data/sorbet/rbi/gems/simplecov_json_formatter@0.1.2.rbi +8 -0
- data/sorbet/rbi/gems/spoom@1.1.15.rbi +1549 -0
- data/sorbet/rbi/gems/tapioca@0.7.3.rbi +1718 -0
- data/sorbet/rbi/gems/thor@1.2.1.rbi +844 -0
- data/sorbet/rbi/gems/unicode-display_width@1.7.0.rbi +22 -0
- data/sorbet/rbi/gems/unparser@0.6.2.rbi +8 -0
- data/sorbet/rbi/gems/vcr@5.0.0.rbi +699 -0
- data/sorbet/rbi/gems/webmock@3.12.2.rbi +662 -0
- data/sorbet/rbi/gems/yard-sorbet@0.8.0.rbi +268 -0
- data/sorbet/rbi/gems/yard@0.9.26.rbi +4048 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +4 -0
- data/spec/lib/workos/audit_logs_spec.rb +151 -0
- data/spec/lib/workos/audit_trail_spec.rb +146 -0
- data/spec/lib/workos/configuration_spec.rb +61 -0
- data/spec/lib/workos/directory_sync_spec.rb +492 -0
- data/spec/lib/workos/directory_user_spec.rb +36 -0
- data/spec/lib/workos/event_spec.rb +88 -0
- data/spec/lib/workos/mfa_spec.rb +281 -0
- data/spec/lib/workos/organizations_spec.rb +257 -0
- data/spec/lib/workos/passwordless_spec.rb +77 -0
- data/spec/lib/workos/portal_spec.rb +87 -0
- data/spec/lib/workos/sso_spec.rb +650 -0
- data/spec/lib/workos/webhooks_spec.rb +236 -0
- data/spec/spec_helper.rb +56 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event.yml +59 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_custom_idempotency_key.yml +60 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_invalid.yml +59 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export.yml +76 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export_with_filters.yml +77 -0
- data/spec/support/fixtures/vcr_cassettes/audit_logs/get_export.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event.yml +65 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_custom_idempotency_key.yml +67 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_invalid.yml +68 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_and_payload.yml +131 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_different_payload.yml +134 -0
- data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +61 -0
- data/spec/support/fixtures/vcr_cassettes/base/execute_request_unauthenticated.yml +66 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_invalid_id.yml +83 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_valid_id.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group_with_invalid_id.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +83 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user_with_invalid_id.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +87 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +89 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_domain.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +85 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_no_options.yml +93 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +85 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +90 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +90 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +90 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +186 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +88 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +194 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +186 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +189 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_no_options.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/events/list_events_with_after.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/events/list_events_with_event.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/events/list_events_with_no_options.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/events/list_events_with_range.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_sms_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/delete_factor.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_invalid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_expired.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_invalid.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid_is_false.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/organization/create.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/organization/create_invalid.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_different_payload.yml +155 -0
- data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_payload.yml +154 -0
- data/spec/support/fixtures/vcr_cassettes/organization/create_with_idempotency_key.yml +79 -0
- data/spec/support/fixtures/vcr_cassettes/organization/delete.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/organization/delete_invalid.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/organization/get.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/organization/list.yml +87 -0
- data/spec/support/fixtures/vcr_cassettes/organization/update.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/passwordless/create_session.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/passwordless/create_session_invalid.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/passwordless/send_session.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/passwordless/send_session_invalid.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_audit_logs.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_invalid.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_sso.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +83 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +90 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +83 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +89 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
- data/spec/support/profile.txt +1 -0
- data/spec/support/shared_examples/client_spec.rb +30 -0
- data/spec/support/webhook_payload.txt +1 -0
- data/workosv2.gemspec +38 -0
- metadata +531 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
describe WorkOSV2::AuditLogs do
|
5
|
+
it_behaves_like 'client'
|
6
|
+
|
7
|
+
before do
|
8
|
+
WorkOSV2.configure do |config|
|
9
|
+
config.key = 'example_api_key'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.create_event' do
|
14
|
+
context 'with valid event payload' do
|
15
|
+
let(:valid_event) do
|
16
|
+
{
|
17
|
+
action: 'user.signed_in',
|
18
|
+
occurred_at: '2022-08-22T15:04:19.704Z',
|
19
|
+
actor: {
|
20
|
+
id: 'user_123',
|
21
|
+
type: 'user',
|
22
|
+
name: 'User',
|
23
|
+
metadata: {
|
24
|
+
foo: 'bar',
|
25
|
+
},
|
26
|
+
},
|
27
|
+
targets: [{
|
28
|
+
id: 'team_123',
|
29
|
+
type: 'team',
|
30
|
+
name: 'Team',
|
31
|
+
metadata: {
|
32
|
+
foo: 'bar',
|
33
|
+
},
|
34
|
+
}],
|
35
|
+
context: {
|
36
|
+
location: '1.1.1.1',
|
37
|
+
user_agent: 'Mozilla',
|
38
|
+
},
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with idempotency key' do
|
43
|
+
it 'creates an event' do
|
44
|
+
VCR.use_cassette 'audit_logs/create_event_custom_idempotency_key', match_requests_on: %i[path body] do
|
45
|
+
response = described_class.create_event(
|
46
|
+
organization: 'org_123',
|
47
|
+
event: valid_event,
|
48
|
+
idempotency_key: 'idempotency_key',
|
49
|
+
)
|
50
|
+
|
51
|
+
expect(response).to eq T::Private::Types::Void::VOID
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'without idempotency key' do
|
57
|
+
it 'creates an event' do
|
58
|
+
VCR.use_cassette 'audit_logs/create_event', match_requests_on: %i[path body] do
|
59
|
+
response = described_class.create_event(
|
60
|
+
organization: 'org_123',
|
61
|
+
event: valid_event,
|
62
|
+
)
|
63
|
+
|
64
|
+
expect(response).to eq T::Private::Types::Void::VOID
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with invalid event' do
|
70
|
+
it 'returns error' do
|
71
|
+
VCR.use_cassette 'audit_logs/create_event_invalid', match_requests_on: %i[path body] do
|
72
|
+
described_class.create_event(
|
73
|
+
organization: 'org_123',
|
74
|
+
event: valid_event,
|
75
|
+
)
|
76
|
+
rescue WorkOSV2::InvalidRequestError => e
|
77
|
+
expect(
|
78
|
+
e.message,
|
79
|
+
).to eq 'Status 400, Invalid Audit Log event - request ID: 1cf9b8e7-5910-4a6d-a333-46bcf841422e'
|
80
|
+
expect(e.code).to eq 'invalid_audit_log'
|
81
|
+
expect(e.errors.count).to eq 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.create_export' do
|
89
|
+
context 'without filters applied' do
|
90
|
+
it 'creates an event' do
|
91
|
+
VCR.use_cassette 'audit_logs/create_export', match_requests_on: %i[path body] do
|
92
|
+
audit_log_export = described_class.create_export(
|
93
|
+
organization: 'org_123',
|
94
|
+
range_start: '2022-06-22T15:04:19.704Z',
|
95
|
+
range_end: '2022-08-22T15:04:19.704Z',
|
96
|
+
)
|
97
|
+
|
98
|
+
expect(audit_log_export).to have_attributes(
|
99
|
+
object: 'audit_log_export',
|
100
|
+
id: 'audit_log_export_123',
|
101
|
+
state: 'pending',
|
102
|
+
url: nil,
|
103
|
+
created_at: '2022-08-22T15:04:19.704Z',
|
104
|
+
updated_at: '2022-08-22T15:04:19.704Z',
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with filters applied' do
|
111
|
+
it 'creates an export' do
|
112
|
+
VCR.use_cassette 'audit_logs/create_export_with_filters', match_requests_on: %i[path body] do
|
113
|
+
audit_log_export = described_class.create_export(
|
114
|
+
organization: 'org_123',
|
115
|
+
range_start: '2022-06-22T15:04:19.704Z',
|
116
|
+
range_end: '2022-08-22T15:04:19.704Z',
|
117
|
+
actions: ['user.signed_in'],
|
118
|
+
actors: ['Jon Smith'],
|
119
|
+
actor_names: ['Jon Smith'],
|
120
|
+
actor_ids: ['user_123'],
|
121
|
+
targets: %w[user team],
|
122
|
+
)
|
123
|
+
|
124
|
+
expect(audit_log_export.object).to eq 'audit_log_export'
|
125
|
+
expect(audit_log_export.id).to eq 'audit_log_export_123'
|
126
|
+
expect(audit_log_export.state).to eq 'pending'
|
127
|
+
expect(audit_log_export.url).to eq nil
|
128
|
+
expect(audit_log_export.created_at).to eq '2022-08-22T15:04:19.704Z'
|
129
|
+
expect(audit_log_export.updated_at).to eq '2022-08-22T15:04:19.704Z'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '.get_export' do
|
136
|
+
it 'returns an export' do
|
137
|
+
VCR.use_cassette 'audit_logs/get_export', match_requests_on: %i[path] do
|
138
|
+
audit_log_export = described_class.get_export(
|
139
|
+
id: 'audit_log_export_123',
|
140
|
+
)
|
141
|
+
|
142
|
+
expect(audit_log_export.object).to eq 'audit_log_export'
|
143
|
+
expect(audit_log_export.id).to eq 'audit_log_export_123'
|
144
|
+
expect(audit_log_export.state).to eq 'ready'
|
145
|
+
expect(audit_log_export.url).to eq 'https://audit-logs.com/download.csv'
|
146
|
+
expect(audit_log_export.created_at).to eq '2022-08-22T15:04:19.704Z'
|
147
|
+
expect(audit_log_export.updated_at).to eq '2022-08-22T15:04:19.704Z'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
describe WorkOSV2::AuditTrail do
|
5
|
+
it_behaves_like 'client'
|
6
|
+
|
7
|
+
describe '.create_event' do
|
8
|
+
context 'with valid event payload' do
|
9
|
+
let(:valid_event) do
|
10
|
+
{
|
11
|
+
group: 'Terrace House',
|
12
|
+
location: '1.1.1.1',
|
13
|
+
action: 'house.created',
|
14
|
+
action_type: 'C',
|
15
|
+
actor_name: 'Daiki Miyagi',
|
16
|
+
actor_id: 'user_12345',
|
17
|
+
target_name: 'Ryota Yamasato',
|
18
|
+
target_id: 'user_67890',
|
19
|
+
occurred_at: '2020-01-10T15:30:00-05:00',
|
20
|
+
metadata: {
|
21
|
+
a: 'b',
|
22
|
+
},
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with idempotency key' do
|
27
|
+
context 'when idempotency key is used once' do
|
28
|
+
it 'creates an event' do
|
29
|
+
VCR.use_cassette('audit_trail/create_event_custom_idempotency_key') do
|
30
|
+
response = described_class.create_event(
|
31
|
+
event: valid_event,
|
32
|
+
idempotency_key: 'key',
|
33
|
+
)
|
34
|
+
|
35
|
+
expect(response.code).to eq '201'
|
36
|
+
json = JSON.parse(response.body)
|
37
|
+
expect(json['success']).to be true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when idempotency key is used more than once' do
|
43
|
+
context 'with duplicate event payloads' do
|
44
|
+
it 'creates an event' do
|
45
|
+
VCR.use_cassette('audit_trail/create_events_duplicate_idempotency_key_and_payload') do
|
46
|
+
response1 = described_class.create_event(
|
47
|
+
event: valid_event,
|
48
|
+
idempotency_key: 'foo',
|
49
|
+
)
|
50
|
+
response2 = described_class.create_event(
|
51
|
+
event: valid_event,
|
52
|
+
idempotency_key: 'foo',
|
53
|
+
)
|
54
|
+
|
55
|
+
expect(response1.code).to eq '201'
|
56
|
+
json1 = JSON.parse(response1.body)
|
57
|
+
expect(json1['success']).to be true
|
58
|
+
|
59
|
+
expect(response2.code).to eq '201'
|
60
|
+
json2 = JSON.parse(response1.body)
|
61
|
+
expect(json2['success']).to be true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with different event payloads' do
|
67
|
+
it 'raises an error' do
|
68
|
+
VCR.use_cassette('audit_trail/create_events_duplicate_idempotency_key_different_payload') do
|
69
|
+
described_class.create_event(
|
70
|
+
event: valid_event,
|
71
|
+
idempotency_key: 'bar',
|
72
|
+
)
|
73
|
+
|
74
|
+
payload = valid_event.clone
|
75
|
+
payload[:actor_name] = 'Tetsuya Sugaya'
|
76
|
+
|
77
|
+
expect do
|
78
|
+
described_class.create_event(
|
79
|
+
event: payload,
|
80
|
+
idempotency_key: 'bar',
|
81
|
+
)
|
82
|
+
end.to raise_error(
|
83
|
+
WorkOSV2::InvalidRequestError,
|
84
|
+
/Status 400, Another idempotency key \(bar\) with different request parameters was found. Please use a different idempotency key./,
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with no idempotency key' do
|
93
|
+
it 'creates an event' do
|
94
|
+
VCR.use_cassette('audit_trail/create_event') do
|
95
|
+
response = described_class.create_event(event: valid_event)
|
96
|
+
|
97
|
+
expect(response.code).to eq '201'
|
98
|
+
json = JSON.parse(response.body)
|
99
|
+
expect(json['success']).to be true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with invalid event payload' do
|
106
|
+
let(:invalid_event) do
|
107
|
+
{
|
108
|
+
group: 'Terrace House',
|
109
|
+
location: '1.1.1.1',
|
110
|
+
action: 'house.created',
|
111
|
+
actor_name: 'Daiki Miyagi',
|
112
|
+
actor_id: 'user_12345',
|
113
|
+
target_name: 'Ryota Yamasato',
|
114
|
+
target_id: 'user_67890',
|
115
|
+
occurred_at: '2020-01-10T15:30:00-05:00',
|
116
|
+
metadata: {
|
117
|
+
a: 'b',
|
118
|
+
},
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'raises an error' do
|
123
|
+
VCR.use_cassette('audit_trail/create_event_invalid') do
|
124
|
+
expect do
|
125
|
+
described_class.create_event(event: invalid_event)
|
126
|
+
end.to raise_error(
|
127
|
+
WorkOSV2::InvalidRequestError,
|
128
|
+
/Status 422, Validation failed \(action_type: action_type must be a string\)/,
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '.get_events' do
|
136
|
+
context 'with no options' do
|
137
|
+
it 'returns events' do
|
138
|
+
VCR.use_cassette('audit_trail/get_events') do
|
139
|
+
events = described_class.get_events
|
140
|
+
|
141
|
+
expect(events.size).to eq(2)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
describe WorkOSV2 do
|
5
|
+
describe '.configure' do
|
6
|
+
context 'with key and no timeout' do
|
7
|
+
before do
|
8
|
+
WorkOSV2.configure do |config|
|
9
|
+
config.key = 'example_api_key'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets the key and default timeout configuration' do
|
14
|
+
expect(WorkOSV2.config.key).to eq('example_api_key')
|
15
|
+
expect(WorkOSV2.config.timeout).to eq(60)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with key and timeout' do
|
20
|
+
before do
|
21
|
+
WorkOSV2.configure do |config|
|
22
|
+
config.key = 'example_api_key'
|
23
|
+
config.timeout = 120
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'sets the key and timeout configuration' do
|
28
|
+
expect(WorkOSV2.config.key).to eq('example_api_key')
|
29
|
+
expect(WorkOSV2.config.timeout).to eq(120)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe WorkOSV2::Configuration do
|
36
|
+
describe '.key!' do
|
37
|
+
context 'with key set' do
|
38
|
+
before do
|
39
|
+
WorkOSV2.config.key = 'example_api_key'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns the key' do
|
43
|
+
expect(WorkOSV2.config.key!).to eq('example_api_key')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with key not set' do
|
48
|
+
before do
|
49
|
+
WorkOSV2.config.key = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'throws an error' do
|
53
|
+
expect do
|
54
|
+
WorkOSV2.config.key!
|
55
|
+
end.to raise_error(
|
56
|
+
'`WorkOSV2.config.key` not set',
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|