diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index f3f0ddd968a6c2332be047ce7cecf15f95187536..0d6f289f5f5748c3338785683a2f9e4adacb01ff 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -169,6 +169,7 @@ def sign_in_user_flow(auth_user_class) # available in the logs for this request. Gitlab::ApplicationContext.push(user: user) log_audit_event(user, with: oauth['provider']) + Gitlab::Tracking.event(self.class.name, "#{oauth['provider']}_sso", user: user) if new_user set_remember_me(user) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 8161afcedb50339dee8ac9190b1ebfbdaa2898f9..1a13b8ca6e53428d200706d1e25eec00e7335755 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -111,8 +111,11 @@ def build_resource(hash = nil) super end + # overridden by EE module def after_request_hook(user) - # overridden by EE module + return unless user.persisted? + + Gitlab::Tracking.event(self.class.name, 'successfully_submitted_form', user: user) end def after_sign_up_path_for(user) @@ -226,12 +229,14 @@ def load_recaptcha Gitlab::Recaptcha.load_configurations! end + # overridden by EE module def set_resource_fields return unless set_blocked_pending_approval? resource.state = User::BLOCKED_PENDING_APPROVAL_STATE end + # overridden by EE module def set_blocked_pending_approval? Gitlab::CurrentSettings.require_admin_approval_after_user_signup end diff --git a/ee/spec/requests/trial_registrations_controller_spec.rb b/ee/spec/requests/trial_registrations_controller_spec.rb index c20a4e4700598772c4d0ce67189648ea39e5fb94..260bd5758e96b442b20f76fd17dbbca0fc249ee4 100644 --- a/ee/spec/requests/trial_registrations_controller_spec.rb +++ b/ee/spec/requests/trial_registrations_controller_spec.rb @@ -10,7 +10,7 @@ stub_feature_flags(arkose_labs_signup_challenge: false) end - describe 'POST new' do + describe 'POST create' do let(:user_params) do build_stubbed(:user) .slice(:first_name, :last_name, :email, :username, :password) @@ -35,5 +35,36 @@ expect(User.last.email_opted_in).to be true end end + + context 'with snowplow tracking', :snowplow do + subject(:post_create) do + post trial_registrations_path, params: { user: user_params } + end + + context 'when the password is weak' do + let(:user_params) { super().merge(password: '1') } + + it 'does not track failed form submission' do + post_create + + expect_no_snowplow_event( + category: described_class.name, + action: 'successfully_submitted_form' + ) + end + end + + context 'when the password is not weak' do + it 'tracks successful form submission' do + post_create + + expect_snowplow_event( + category: described_class.name, + action: 'successfully_submitted_form', + user: User.find_by(email: user_params[:email]) + ) + end + end + end end end diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 0560ccb25dd67d858386dde8826887fdfb3c5c73..ab3f3fd397d3ab1e7034a82ae4707e323725364a 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -391,6 +391,32 @@ def stub_route_as(path) end end end + + context 'with snowplow tracking', :snowplow do + let(:provider) { 'google_oauth2' } + let(:extern_uid) { 'my-uid' } + + context 'when sign_in' do + it 'does not track the event' do + post provider + expect_no_snowplow_event + end + end + + context 'when sign_up' do + let(:user) { double(email: generate(:email)) } + + it 'tracks the event' do + post provider + + expect_snowplow_event( + category: described_class.name, + action: "#{provider}_sso", + user: User.find_by(email: user.email) + ) + end + end + end end describe '#saml' do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index b34244b4c141c71f3fcac126610afbc25a0f6e61..e0ed58f291e6b44d35b745f8c58d626ccabdafde 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -36,7 +36,7 @@ let(:session_params) { {} } - subject { post(:create, params: user_params, session: session_params) } + subject(:post_create) { post(:create, params: user_params, session: session_params) } context '`blocked_pending_approval` state' do context 'when the `require_admin_approval_after_user_signup` setting is turned on' do @@ -484,18 +484,19 @@ render_views let_it_be(:new_user_params) { { new_user: base_user_params.merge({ password: "password" }) } } - subject { post(:create, params: new_user_params) } + subject(:post_create) { post(:create, params: new_user_params) } it 'renders the form with errors' do - expect { subject }.not_to change(User, :count) + expect { post_create }.not_to change(User, :count) expect(controller.current_user).to be_nil expect(response).to render_template(:new) expect(response.body).to include(_('Password must not contain commonly used combinations of words and letters')) end - it 'tracks the error' do - subject + it 'tracks a weak password error' do + post_create + expect_snowplow_event( category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', action: 'track_weak_password_error', @@ -503,16 +504,36 @@ method: 'create' ) end + + it 'does not track failed form submission' do + post_create + + expect_no_snowplow_event( + category: described_class.name, + action: 'successfully_submitted_form' + ) + end end context 'when the password is not weak' do it 'does not track a weak password error' do - subject + post_create + expect_no_snowplow_event( category: 'Gitlab::Tracking::Helpers::WeakPasswordErrorEvent', action: 'track_weak_password_error' ) end + + it 'tracks successful form submission' do + post_create + + expect_snowplow_event( + category: described_class.name, + action: 'successfully_submitted_form', + user: User.find_by(email: base_user_params[:email]) + ) + end end context 'with preferred language' do