Skip to content

Commit

Permalink
Merge pull request #143 from Esri/bug/username
Browse files Browse the repository at this point in the history
fix(auth): better regex match for usernames
  • Loading branch information
patrickarlt authored Mar 3, 2018
2 parents d657b57 + d38a7fb commit 04ec689
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class UserSession implements IAuthenticationManager {
}

const match = win.location.href.match(
/access_token=(.+)&expires_in=(.+)&username=(.+)/
/access_token=(.+)&expires_in=(.+)&username=([^&]+)/
);

if (!match) {
Expand Down
38 changes: 19 additions & 19 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("UserSession", () => {
refreshToken: "refreshToken",
refreshTokenExpires: TOMORROW,
refreshTokenTTL: 1440,
username: "casey",
username: "c@sey",
password: "123456"
});

Expand All @@ -33,7 +33,7 @@ describe("UserSession", () => {
expect(session2.tokenExpires).toEqual(TOMORROW);
expect(session2.refreshToken).toEqual("refreshToken");
expect(session2.refreshTokenExpires).toEqual(TOMORROW);
expect(session2.username).toEqual("casey");
expect(session2.username).toEqual("c@sey");
expect(session2.password).toEqual("123456");
expect(session2.tokenDuration).toEqual(20160);
expect(session2.refreshTokenTTL).toEqual(1440);
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("UserSession", () => {
{
access_token: "new",
expires_in: 1800,
username: "casey"
username: "c@sey"
},
{ times: 2, method: "POST" }
);
Expand Down Expand Up @@ -266,14 +266,14 @@ describe("UserSession", () => {
describe(".refreshSession()", () => {
it("should refresh with a username and password if expired", done => {
const session = new UserSession({
username: "casey",
username: "c@sey",
password: "123456"
});

fetchMock.postOnce("https://www.arcgis.com/sharing/rest/generateToken", {
token: "token",
expires: TOMORROW.getTime(),
username: " casey"
username: " c@sey"
});

session
Expand All @@ -292,15 +292,15 @@ describe("UserSession", () => {
const session = new UserSession({
clientId: "clientId",
token: "token",
username: "casey",
username: "c@sey",
refreshToken: "refreshToken",
refreshTokenExpires: TOMORROW
});

fetchMock.postOnce("https://www.arcgis.com/sharing/rest/oauth2/token", {
access_token: "newToken",
expires_in: 60,
username: " casey"
username: " c@sey"
});

session
Expand All @@ -319,7 +319,7 @@ describe("UserSession", () => {
const session = new UserSession({
clientId: "clientId",
token: "token",
username: "casey",
username: "c@sey",
refreshToken: "refreshToken",
refreshTokenExpires: YESTERDAY,
redirectUri: "https://example-app.com/redirect-uri"
Expand All @@ -328,7 +328,7 @@ describe("UserSession", () => {
fetchMock.postOnce("https://www.arcgis.com/sharing/rest/oauth2/token", {
access_token: "newToken",
expires_in: 60,
username: " casey",
username: " c@sey",
refresh_token: "newRefreshToken"
});

Expand All @@ -350,7 +350,7 @@ describe("UserSession", () => {
const session = new UserSession({
clientId: "clientId",
token: "token",
username: "casey"
username: "c@sey"
});

session.refreshSession().catch(e => {
Expand All @@ -374,7 +374,7 @@ describe("UserSession", () => {
{
access_token: "new",
expires_in: 1800,
username: "casey"
username: "c@sey"
},
{ times: 1, method: "POST" }
);
Expand Down Expand Up @@ -413,7 +413,7 @@ describe("UserSession", () => {
)
.then(session => {
expect(session.token).toBe("token");
expect(session.username).toBe("Casey");
expect(session.username).toBe("c@sey");
expect(session.tokenExpires).toBe(TOMORROW);
done();
})
Expand All @@ -430,7 +430,7 @@ describe("UserSession", () => {
MockWindow.__ESRI_REST_AUTH_HANDLER_clientId(null, {
token: "token",
expires: TOMORROW,
username: "Casey"
username: "c@sey"
});
});

Expand Down Expand Up @@ -488,7 +488,7 @@ describe("UserSession", () => {
const MockWindow = {
location: {
href:
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=casey"
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c@sey&persist=true"
},
get parent() {
return this;
Expand All @@ -505,7 +505,7 @@ describe("UserSession", () => {

expect(session.token).toBe("token");
expect(session.tokenExpires.getTime()).toBeGreaterThan(Date.now());
expect(session.username).toBe("casey");
expect(session.username).toBe("c@sey");
});

it("should callback to create a new user session if finds a valid opener", done => {
Expand All @@ -517,7 +517,7 @@ describe("UserSession", () => {
oauthInfo: IFetchTokenResponse
) {
expect(oauthInfo.token).toBe("token");
expect(oauthInfo.username).toBe("casey");
expect(oauthInfo.username).toBe("c@sey");
expect(oauthInfo.expires.getTime()).toBeGreaterThan(Date.now());
}
}
Expand All @@ -527,7 +527,7 @@ describe("UserSession", () => {
},
location: {
href:
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=casey"
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c@sey"
}
};

Expand All @@ -548,7 +548,7 @@ describe("UserSession", () => {
oauthInfo: IFetchTokenResponse
) {
expect(oauthInfo.token).toBe("token");
expect(oauthInfo.username).toBe("casey");
expect(oauthInfo.username).toBe("c@sey");
expect(oauthInfo.expires.getTime()).toBeGreaterThan(Date.now());
}
},
Expand All @@ -557,7 +557,7 @@ describe("UserSession", () => {
},
location: {
href:
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=casey"
"https://example-app.com/redirect-uri#access_token=token&expires_in=1209600&username=c@sey"
}
};

Expand Down

0 comments on commit 04ec689

Please sign in to comment.