Skip to content

Commit 8301624

Browse files
committed
Formatting, licenses
1 parent 2784b15 commit 8301624

File tree

7 files changed

+147
-48
lines changed

7 files changed

+147
-48
lines changed

packages-exp/auth-exp/test/integration/webdriver/redirect.test.ts

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
*/
1717

1818
// eslint-disable-next-line import/no-extraneous-dependencies
19-
import { OperationType, UserCredential, User, OAuthCredential } from '@firebase/auth-exp';
19+
import {
20+
OperationType,
21+
UserCredential,
22+
User,
23+
OAuthCredential
24+
} from '@firebase/auth-exp';
2025
import { expect, use } from 'chai';
2126
import { IdPPage } from './util/idp_page';
2227
import * as chaiAsPromised from 'chai-as-promised';
@@ -56,10 +61,11 @@ browserDescribe('WebDriver redirect IdP test', driver => {
5661
expect(redirectResult.user).to.eql(currentUser);
5762
});
5863

59-
6064
it('can link with another account account', async () => {
6165
// First, sign in anonymously
62-
const {user: anonUser}: UserCredential = await driver.call(AnonFunction.SIGN_IN_ANONYMOUSLY);
66+
const { user: anonUser }: UserCredential = await driver.call(
67+
AnonFunction.SIGN_IN_ANONYMOUSLY
68+
);
6369

6470
// Then, link with redirect
6571
driver.callNoWait(RedirectFunction.IDP_LINK_REDIRECT);
@@ -89,14 +95,18 @@ browserDescribe('WebDriver redirect IdP test', driver => {
8995
// Generate a credential, then store it on the window before logging out
9096
await driver.reinitOnRedirect();
9197
const first = await driver.getUserSnapshot();
92-
const cred: OAuthCredential = await driver.call(RedirectFunction.GENERATE_CREDENTIAL_FROM_RESULT);
98+
const cred: OAuthCredential = await driver.call(
99+
RedirectFunction.GENERATE_CREDENTIAL_FROM_RESULT
100+
);
93101
expect(cred.accessToken).to.be.a('string');
94102
expect(cred.idToken).to.be.a('string');
95103
expect(cred.signInMethod).to.eq('google.com');
96104

97105
// We've now generated that credential. Sign out and sign back in using it
98106
await driver.call(CoreFunction.SIGN_OUT);
99-
const {user: second}: UserCredential = await driver.call(RedirectFunction.SIGN_IN_WITH_REDIRECT_CREDENTIAL);
107+
const { user: second }: UserCredential = await driver.call(
108+
RedirectFunction.SIGN_IN_WITH_REDIRECT_CREDENTIAL
109+
);
100110
expect(second.uid).to.eq(first.uid);
101111
expect(second.providerData).to.eql(first.providerData);
102112
});
@@ -117,15 +127,23 @@ browserDescribe('WebDriver redirect IdP test', driver => {
117127
// Try to sign in with an unverified Facebook account
118128
// TODO: Convert this to the widget once unverified accounts work
119129
// Come back and verify error / prepare for link
120-
await expect(driver.call(RedirectFunction.TRY_TO_SIGN_IN_UNVERIFIED, '"[email protected]"')).to.be.rejected.and.eventually.have.property('code', 'auth/account-exists-with-different-credential');
121-
130+
await expect(
131+
driver.call(RedirectFunction.TRY_TO_SIGN_IN_UNVERIFIED, '"[email protected]"')
132+
).to.be.rejected.and.eventually.have.property(
133+
'code',
134+
'auth/account-exists-with-different-credential'
135+
);
136+
122137
// Now do the link
123138
await driver.call(RedirectFunction.LINK_WITH_ERROR_CREDENTIAL);
124-
139+
125140
// Check the user for both providers
126141
const user = await driver.getUserSnapshot();
127142
expect(user.uid).to.eq(original.uid);
128-
expect(user.providerData.map(d => d.providerId)).to.have.members(['google.com', 'facebook.com']);
143+
expect(user.providerData.map(d => d.providerId)).to.have.members([
144+
'google.com',
145+
'facebook.com'
146+
]);
129147
});
130148

131149
context('with existing user', () => {
@@ -134,17 +152,23 @@ browserDescribe('WebDriver redirect IdP test', driver => {
134152

135153
beforeEach(async () => {
136154
// Create a couple existing users
137-
let cred: UserCredential = await driver.call(RedirectFunction.CREATE_FAKE_GOOGLE_USER, '"[email protected]"');
155+
let cred: UserCredential = await driver.call(
156+
RedirectFunction.CREATE_FAKE_GOOGLE_USER,
157+
158+
);
138159
user1 = cred.user;
139-
cred = await driver.call(RedirectFunction.CREATE_FAKE_GOOGLE_USER, '"[email protected]"');
160+
cred = await driver.call(
161+
RedirectFunction.CREATE_FAKE_GOOGLE_USER,
162+
163+
);
140164
user2 = cred.user;
141165
await driver.call(CoreFunction.SIGN_OUT);
142166
});
143167

144168
it('a user can sign in again', async () => {
145169
// Sign in using pre-poulated user
146170
await driver.callNoWait(RedirectFunction.IDP_REDIRECT);
147-
171+
148172
// This time, select an existing account
149173
const widget = new IdPPage(driver.webDriver);
150174
await widget.pageLoad();
@@ -157,7 +181,7 @@ browserDescribe('WebDriver redirect IdP test', driver => {
157181
expect(user.email).to.eq(user1.email);
158182
});
159183

160-
it('reauthenticate works for the correct user', async() => {
184+
it('reauthenticate works for the correct user', async () => {
161185
// Sign in using pre-poulated user
162186
await driver.callNoWait(RedirectFunction.IDP_REDIRECT);
163187

@@ -176,12 +200,12 @@ browserDescribe('WebDriver redirect IdP test', driver => {
176200
await widget.pageLoad();
177201
await widget.selectExistingAccountByEmail(user1.email!);
178202

179-
await driver.reinitOnRedirect();
203+
await driver.reinitOnRedirect();
180204
user = await driver.getUserSnapshot();
181205
expect(user.uid).to.eq(user1.uid);
182206
expect(user.email).to.eq(user1.email);
183-
})
184-
207+
});
208+
185209
it('reauthenticate throws for wrong user', async () => {
186210
// Sign in using pre-poulated user
187211
await driver.callNoWait(RedirectFunction.IDP_REDIRECT);
@@ -195,15 +219,20 @@ browserDescribe('WebDriver redirect IdP test', driver => {
195219
await driver.callNoWait(RedirectFunction.IDP_REAUTH_REDIRECT);
196220
await widget.pageLoad();
197221
await widget.selectExistingAccountByEmail(user2.email!);
198-
222+
199223
await driver.reinitOnRedirect();
200-
await expect(driver.call(RedirectFunction.REDIRECT_RESULT)).to.be.rejected.and.eventually.have.property('code', 'auth/user-mismatch');
224+
await expect(
225+
driver.call(RedirectFunction.REDIRECT_RESULT)
226+
).to.be.rejected.and.eventually.have.property(
227+
'code',
228+
'auth/user-mismatch'
229+
);
201230
});
202231

203232
it('handles aborted sign ins', async () => {
204233
await driver.callNoWait(RedirectFunction.IDP_REDIRECT);
205234
const widget = new IdPPage(driver.webDriver);
206-
235+
207236
// Don't actually sign in; go back to the previous page
208237
await widget.pageLoad();
209238
await driver.goToTestPage();
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
import {
2-
signInAnonymously,
3-
} from '@firebase/auth-exp';
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { signInAnonymously } from '@firebase/auth-exp';
419

520
export async function anonymous() {
621
const userCred = await signInAnonymously(auth);
722
return userCred;
8-
};
23+
}

packages-exp/auth-exp/test/integration/webdriver/static/core.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
export function reset() {
219
sessionStorage.clear();
320
localStorage.clear();
@@ -8,13 +25,13 @@ export function reset() {
825
del.addEventListener('error', () => resolve());
926
del.addEventListener('blocked', () => resolve());
1027
});
11-
};
28+
}
1229

1330
export function authInit() {
1431
return new Promise(resolve => {
1532
auth.onAuthStateChanged(() => resolve());
1633
});
17-
};
34+
}
1835

1936
export async function userSnap() {
2037
return auth.currentUser;

packages-exp/auth-exp/test/integration/webdriver/static/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as redirect from './redirect'
18+
import * as redirect from './redirect';
1919
import * as anonymous from './anonymous';
2020
import * as core from './core';
2121
import { initializeApp } from '@firebase/app-exp';
22-
import {
23-
getAuth,
24-
useAuthEmulator
25-
} from '@firebase/auth-exp';
22+
import { getAuth, useAuthEmulator } from '@firebase/auth-exp';
2623

2724
window.core = core;
2825
window.anonymous = anonymous;

packages-exp/auth-exp/test/integration/webdriver/static/redirect.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
import {
219
FacebookAuthProvider,
320
getRedirectResult,
@@ -7,11 +24,13 @@ import {
724
OAuthProvider,
825
reauthenticateWithRedirect,
926
signInWithCredential,
10-
signInWithRedirect,
27+
signInWithRedirect
1128
} from '@firebase/auth-exp';
1229

1330
export function idpRedirect(optProvider) {
14-
const provider = optProvider ? new OAuthProvider(optProvider) : new GoogleAuthProvider();
31+
const provider = optProvider
32+
? new OAuthProvider(optProvider)
33+
: new GoogleAuthProvider();
1534
signInWithRedirect(auth, provider);
1635
}
1736

@@ -46,19 +65,23 @@ export async function linkWithErrorCredential() {
4665

4766
export function createFakeGoogleUser(email) {
4867
return signInWithCredential(
49-
auth,
50-
GoogleAuthProvider.credential(
51-
`{"sub": "__${email}__", "email": "${email}", "email_verified": true}`
52-
))
68+
auth,
69+
GoogleAuthProvider.credential(
70+
`{"sub": "__${email}__", "email": "${email}", "email_verified": true}`
71+
)
72+
);
5373
}
5474

55-
export async function tryToSignInUnverified(email) {
75+
export async function tryToSignInUnverified(email) {
5676
try {
57-
await signInWithCredential(auth, FacebookAuthProvider.credential(
58-
`{"sub": "$$${email}$$", "email": "${email}", "email_verified": false}`
59-
));
77+
await signInWithCredential(
78+
auth,
79+
FacebookAuthProvider.credential(
80+
`{"sub": "$$${email}$$", "email": "${email}", "email_verified": false}`
81+
)
82+
);
6083
} catch (e) {
6184
window.errorCred = FacebookAuthProvider.credentialFromError(e);
6285
throw e;
6386
}
64-
}
87+
}

packages-exp/auth-exp/test/integration/webdriver/util/auth_driver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class AuthDriver {
5252
// serialization which blows up the whole thing. It's okay though; this is
5353
// an integration test: we don't care about the internal (hidden) values of
5454
// these objects.
55-
const {type, value}: {type: string, value: string} = await this.webDriver.executeAsyncScript(`
55+
const { type, value }: { type: string; value: string } = await this
56+
.webDriver.executeAsyncScript(`
5657
var callback = arguments[arguments.length - 1];
5758
${fn}(${argString}).then(result => {
5859
callback({type: 'success', value: JSON.stringify(result)});
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
/** Available in the browser. See static/anonymous.js */
219
export enum AnonFunction {
3-
SIGN_IN_ANONYMOUSLY = 'anonymous.anonymous',
4-
};
20+
SIGN_IN_ANONYMOUSLY = 'anonymous.anonymous'
21+
}
522

623
/** Available redirect functions. See static/redirect.js */
724
export enum RedirectFunction {
@@ -13,14 +30,14 @@ export enum RedirectFunction {
1330
SIGN_IN_WITH_REDIRECT_CREDENTIAL = 'redirect.signInWithRedirectCredential',
1431
LINK_WITH_ERROR_CREDENTIAL = 'redirect.linkWithErrorCredential',
1532
CREATE_FAKE_GOOGLE_USER = 'redirect.createFakeGoogleUser',
16-
TRY_TO_SIGN_IN_UNVERIFIED = 'redirect.tryToSignInUnverified',
17-
};
33+
TRY_TO_SIGN_IN_UNVERIFIED = 'redirect.tryToSignInUnverified'
34+
}
1835

1936
/** Available core functions within the browser. See static/core.js */
2037
export enum CoreFunction {
2138
RESET = 'core.reset',
2239
AWAIT_AUTH_INIT = 'core.authInit',
2340
USER_SNAPSHOT = 'core.userSnap',
2441
AUTH_SNAPSHOT = 'core.authSnap',
25-
SIGN_OUT = 'core.signOut',
26-
}
42+
SIGN_OUT = 'core.signOut'
43+
}

0 commit comments

Comments
 (0)