Skip to content

Commit

Permalink
Merge pull request #17053 from mozilla/FXA-9752
Browse files Browse the repository at this point in the history
feat(metrics): Add reg_complete backend glean event for third party auth new account creation
  • Loading branch information
LZoog authored Jun 3, 2024
2 parents a7df9a7 + 0e39ca5 commit c603422
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/fxa-auth-server/lib/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ module.exports = function (
config,
mailer,
profile,
statsd
statsd,
glean
);

const { cloudTaskRoutes } = require('./cloud-tasks');
Expand Down
11 changes: 8 additions & 3 deletions packages/fxa-auth-server/lib/routes/linked-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
appleEventHandlers,
AppleSETEvent,
} from './utils/third-party-events';
import { gleanMetrics } from '../metrics/glean';

const HEX_STRING = validators.HEX_STRING;

Expand All @@ -48,7 +49,8 @@ export class LinkedAccountHandler {
private config: ConfigType,
private mailer: any,
private profile: ProfileClient,
private statsd: { increment: (value: string) => void }
private statsd: { increment: (value: string) => void },
private glean: ReturnType<typeof gleanMetrics>
) {
if (config.googleAuthConfig && config.googleAuthConfig.clientId) {
this.googleAuthClient = new OAuth2Client(
Expand Down Expand Up @@ -416,6 +418,7 @@ export class LinkedAccountHandler {
flowBeginTime,
service,
});
this.glean.registration.complete(request, { uid: accountRecord.uid });
}
} else {
// This is an existing user and existing FxA user
Expand Down Expand Up @@ -492,15 +495,17 @@ export const linkedAccountRoutes = (
config: ConfigType,
mailer: any,
profile: ProfileClient,
statsd: any
statsd: any,
glean: ReturnType<typeof gleanMetrics>
) => {
const handler = new LinkedAccountHandler(
log,
db,
config,
mailer,
profile,
statsd
statsd,
glean
);

return [
Expand Down
13 changes: 10 additions & 3 deletions packages/fxa-auth-server/test/local/routes/linked-accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getRoute = require('../../routes_helpers').getRoute;
const mocks = require('../../mocks');
const error = require('../../../lib/error');
const proxyquire = require('proxyquire');
const glean = mocks.mockGlean();

const GOOGLE_PROVIDER = 'google';
const APPLE_PROVIDER = 'apple';
Expand All @@ -29,7 +30,7 @@ const makeRoutes = function (options = {}, requireMocks) {
requireMocks || {}
);

return linkedAccountRoutes(log, db, config, mailer, profile, statsd);
return linkedAccountRoutes(log, db, config, mailer, profile, statsd, glean);
};

function runTest(route, request, assertions) {
Expand Down Expand Up @@ -110,6 +111,7 @@ describe('/linked_account', function () {
),
'/linked_account/login'
);
glean.registration.complete.reset();
});

it('fails if no google config', async () => {
Expand Down Expand Up @@ -161,7 +163,7 @@ describe('/linked_account', function () {
assert.ok(result.sessionToken);
});

it('should create new fxa account from new google account and return session', async () => {
it('should create new fxa account from new google account, return session, emit Glean events', async () => {
mockDB.accountRecord = sinon.spy(() =>
Promise.reject(new error.unknownAccount(mockGoogleUser.email))
);
Expand Down Expand Up @@ -201,6 +203,7 @@ describe('/linked_account', function () {

assert.equal(result.uid, UID);
assert.ok(result.sessionToken);
assert.calledOnce(glean.registration.complete);
});

it('should linking existing fxa account and new google account and return session', async () => {
Expand All @@ -224,6 +227,8 @@ describe('/linked_account', function () {
assert.isTrue(mockDB.createSessionToken.calledOnce);
assert.equal(result.uid, UID);
assert.ok(result.sessionToken);
// should not be called for existing account
assert.notCalled(glean.registration.complete);
});

it('should return session with valid google id token', async () => {
Expand Down Expand Up @@ -336,6 +341,7 @@ describe('/linked_account', function () {
),
'/linked_account/login'
);
glean.registration.complete.reset();
});

it('fails if no apple config', async () => {
Expand Down Expand Up @@ -390,7 +396,7 @@ describe('/linked_account', function () {
assert.ok(result.sessionToken);
});

it('should create new fxa account from new apple account and return session', async () => {
it('should create new fxa account from new apple account, return session, emit Glean events', async () => {
mockDB.accountRecord = sinon.spy(() =>
Promise.reject(new error.unknownAccount(mockAppleUser.email))
);
Expand All @@ -414,6 +420,7 @@ describe('/linked_account', function () {
assert.isTrue(mockDB.createSessionToken.calledOnce);
assert.equal(result.uid, UID);
assert.ok(result.sessionToken);
assert.calledOnce(glean.registration.complete);
});

it('should link existing fxa account and new apple account and return session', async () => {
Expand Down

0 comments on commit c603422

Please sign in to comment.