Skip to content

Commit 39de7ad

Browse files
author
Prithvi Kanherkar
authored
Merge pull request #1854 from AzureAD/extrascopes-append-error-2.0
[msal-common] Fix issue where extraScopesToConsent was not appending scopes correctly
2 parents bcc1ebf + 70d6ac3 commit 39de7ad

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

lib/msal-common/src/request/ScopeSet.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ export class ScopeSet {;
7575
* @param newScope
7676
*/
7777
appendScope(newScope: string): void {
78-
if (StringUtils.isEmpty(newScope)) {
79-
throw ClientAuthError.createAppendEmptyScopeToSetError(newScope);
78+
if (!StringUtils.isEmpty(newScope)) {
79+
this.scopes.add(newScope.trim().toLowerCase());
8080
}
81-
this.scopes.add(newScope.trim().toLowerCase());
8281
}
8382

8483
/**
@@ -87,7 +86,7 @@ export class ScopeSet {;
8786
*/
8887
appendScopes(newScopes: Array<string>): void {
8988
try {
90-
newScopes.forEach(newScope => this.scopes.add(newScope));
89+
newScopes.forEach(newScope => this.appendScope(newScope));
9190
} catch (e) {
9291
throw ClientAuthError.createAppendScopeSetError(e);
9392
}

lib/msal-common/test/request/ScopeSet.spec.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,19 @@ describe("ScopeSet.ts", () => {
127127
});
128128

129129
it("appendScope() does nothing if given scope is empty, null or undefined", () => {
130+
const testScopes = [testScope];
130131
const setAddSpy = sinon.spy(Set.prototype, "add");
131-
132-
expect(() => scopes.appendScope("")).to.throw(ClientAuthError);
133-
expect(() => scopes.appendScope("")).to.throw(ClientAuthErrorMessage.appendEmptyScopeError.desc);
132+
scopes.appendScope("");
134133
expect(setAddSpy.called).to.be.false;
134+
expect(scopes.asArray()).to.be.deep.eq(testScopes);
135135

136-
expect(() => scopes.appendScope(null)).to.throw(ClientAuthError);
137-
expect(() => scopes.appendScope(null)).to.throw(ClientAuthErrorMessage.appendEmptyScopeError.desc);
136+
scopes.appendScope(null);
138137
expect(setAddSpy.called).to.be.false;
138+
expect(scopes.asArray()).to.be.deep.eq(testScopes);
139139

140-
expect(() => scopes.appendScope(undefined)).to.throw(ClientAuthError);
141-
expect(() => scopes.appendScope(undefined)).to.throw(ClientAuthErrorMessage.appendEmptyScopeError.desc);
140+
scopes.appendScope(undefined);
142141
expect(setAddSpy.called).to.be.false;
142+
expect(scopes.asArray()).to.be.deep.eq(testScopes);
143143
});
144144

145145
it("appendScopes() throws error if given array is null or undefined", () => {
@@ -164,6 +164,16 @@ describe("ScopeSet.ts", () => {
164164
expect(scopes.asArray()).to.contain(testScope3);
165165
});
166166

167+
it("appendScopes() trims and converts scopes to lower case before adding", () => {
168+
const testScope2 = "TestScope2";
169+
const expectedTestScope2 = "testscope2";
170+
const testScope3 = " testscope3 ";
171+
const expectedTestScope3 = "testscope3";
172+
scopes.appendScopes([testScope2, testScope3]);
173+
expect(scopes.asArray()).to.contain(expectedTestScope2);
174+
expect(scopes.asArray()).to.contain(expectedTestScope3);
175+
})
176+
167177
it("appendScopes() does not add duplicate scopes", () => {
168178
const unchangedScopes = new ScopeSet([testScope, Constants.OFFLINE_ACCESS_SCOPE]);
169179
const scopeArr = unchangedScopes.asArray();

0 commit comments

Comments
 (0)