|
12 | 12 | allow(telemetry).to receive(:inc) |
13 | 13 | end |
14 | 14 |
|
15 | | - describe '.watch_set_user' do |
16 | | - before { described_class.watch_set_user(gateway) } |
| 15 | + describe '.watch_user_lifecycle' do |
| 16 | + before { described_class.watch_user_lifecycle(gateway) } |
17 | 17 |
|
18 | | - %w[login_success signup].each do |event_type| |
19 | | - context "with #{event_type} event_type" do |
| 18 | + %w[ |
| 19 | + identity.devise.login_success |
| 20 | + identity.devise.login_failure |
| 21 | + identity.devise.signup |
| 22 | + ].each do |event_name| |
| 23 | + _, framework, event_type = event_name.split('.') |
| 24 | + |
| 25 | + context "with #{event_name}" do |
20 | 26 | it 'reports missing_user_login when login is nil' do |
21 | 27 | expect(telemetry).to receive(:inc).with( |
22 | 28 | 'appsec', 'instrum.user_auth.missing_user_login', 1, |
23 | | - tags: {framework: 'devise', event_type: event_type}, |
| 29 | + tags: {framework: framework, event_type: event_type}, |
24 | 30 | ) |
25 | 31 |
|
26 | | - gateway.push('identity.set_user', {id: '123', framework: 'devise', event_type: event_type}) |
| 32 | + gateway.push(event_name, {id: '123'}) |
27 | 33 | end |
28 | 34 |
|
29 | 35 | it 'reports both metrics when login and id are nil' do |
30 | 36 | expect(telemetry).to receive(:inc).with( |
31 | 37 | 'appsec', 'instrum.user_auth.missing_user_login', 1, |
32 | | - tags: {framework: 'devise', event_type: event_type}, |
| 38 | + tags: {framework: framework, event_type: event_type}, |
33 | 39 | ) |
34 | 40 | expect(telemetry).to receive(:inc).with( |
35 | 41 | 'appsec', 'instrum.user_auth.missing_user_id', 1, |
36 | | - tags: {framework: 'devise', event_type: event_type}, |
| 42 | + tags: {framework: framework, event_type: event_type}, |
37 | 43 | ) |
38 | 44 |
|
39 | | - gateway.push('identity.set_user', {framework: 'devise', event_type: event_type}) |
| 45 | + gateway.push(event_name, {}) |
40 | 46 | end |
41 | 47 |
|
42 | 48 | it 'does not report any telemetry when login is present' do |
43 | 49 | expect(telemetry).not_to receive(:inc) |
44 | 50 |
|
45 | | - gateway.push('identity.set_user', {login: 'alice', framework: 'devise', event_type: event_type}) |
| 51 | + gateway.push(event_name, {login: 'alice'}) |
46 | 52 | end |
47 | 53 | end |
48 | 54 | end |
49 | | - |
50 | | - context 'with authenticated_request event_type' do |
51 | | - it 'reports missing_user_id when id is nil' do |
52 | | - expect(telemetry).to receive(:inc).with( |
53 | | - 'appsec', 'instrum.user_auth.missing_user_id', 1, |
54 | | - tags: {framework: 'devise', event_type: 'authenticated_request'}, |
55 | | - ) |
56 | | - |
57 | | - gateway.push('identity.set_user', {framework: 'devise', event_type: 'authenticated_request'}) |
58 | | - end |
59 | | - |
60 | | - it 'does not report missing_user_login even when login is nil' do |
61 | | - expect(telemetry).not_to receive(:inc).with( |
62 | | - 'appsec', 'instrum.user_auth.missing_user_login', anything, anything, |
63 | | - ) |
64 | | - |
65 | | - gateway.push('identity.set_user', {framework: 'devise', event_type: 'authenticated_request'}) |
66 | | - end |
67 | | - |
68 | | - it 'does not report any telemetry when id is present' do |
69 | | - expect(telemetry).not_to receive(:inc) |
70 | | - |
71 | | - gateway.push('identity.set_user', {id: '123', framework: 'devise', event_type: 'authenticated_request'}) |
72 | | - end |
73 | | - end |
74 | | - |
75 | | - context 'when event_type is not set' do |
76 | | - it 'does not report any telemetry' do |
77 | | - expect(telemetry).not_to receive(:inc) |
78 | | - |
79 | | - gateway.push('identity.set_user', {id: '123', framework: 'sdk'}) |
80 | | - end |
81 | | - end |
82 | 55 | end |
83 | 56 |
|
84 | | - describe '.watch_login_failure' do |
85 | | - before { described_class.watch_login_failure(gateway) } |
| 57 | + describe '.watch_authenticated_request' do |
| 58 | + before { described_class.watch_authenticated_request(gateway) } |
86 | 59 |
|
87 | | - it 'reports missing_user_login when login is nil' do |
| 60 | + it 'reports missing_user_id when id is nil' do |
88 | 61 | expect(telemetry).to receive(:inc).with( |
89 | | - 'appsec', 'instrum.user_auth.missing_user_login', 1, |
90 | | - tags: {framework: 'devise', event_type: 'login_failure'}, |
| 62 | + 'appsec', 'instrum.user_auth.missing_user_id', 1, |
| 63 | + tags: {framework: 'devise', event_type: 'authenticated_request'}, |
91 | 64 | ) |
92 | 65 |
|
93 | | - gateway.push('identity.login_failure', {id: '123', framework: 'devise'}) |
| 66 | + gateway.push('identity.devise.authenticated_request', {}) |
94 | 67 | end |
95 | 68 |
|
96 | | - it 'reports both metrics when login and id are nil' do |
97 | | - expect(telemetry).to receive(:inc).with( |
98 | | - 'appsec', 'instrum.user_auth.missing_user_login', 1, |
99 | | - tags: {framework: 'devise', event_type: 'login_failure'}, |
100 | | - ) |
101 | | - expect(telemetry).to receive(:inc).with( |
102 | | - 'appsec', 'instrum.user_auth.missing_user_id', 1, |
103 | | - tags: {framework: 'devise', event_type: 'login_failure'}, |
| 69 | + it 'does not report missing_user_login even when login is nil' do |
| 70 | + expect(telemetry).not_to receive(:inc).with( |
| 71 | + 'appsec', 'instrum.user_auth.missing_user_login', anything, anything, |
104 | 72 | ) |
105 | 73 |
|
106 | | - gateway.push('identity.login_failure', {framework: 'devise'}) |
| 74 | + gateway.push('identity.devise.authenticated_request', {}) |
107 | 75 | end |
108 | 76 |
|
109 | | - it 'does not report any telemetry when login is present' do |
| 77 | + it 'does not report any telemetry when id is present' do |
110 | 78 | expect(telemetry).not_to receive(:inc) |
111 | 79 |
|
112 | | - gateway.push('identity.login_failure', {login: 'alice', framework: 'devise'}) |
| 80 | + gateway.push('identity.devise.authenticated_request', {id: '123'}) |
113 | 81 | end |
114 | 82 | end |
115 | 83 | end |
0 commit comments