Skip to content

Commit

Permalink
Fix unit test failures in auth-state and url services
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianGosebrink committed Jan 4, 2024
1 parent bdc7bff commit 33d69fa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('Auth State Service', () => {
configId: 'configId1',
});

expect(result).toBe({});
expect(result).toEqual({});
});

it('isAuthorized is true returns object', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ describe('CheckAuthService', () => {
userData: null,
idToken: '',
accessToken: '',
configId: '',
});
expect(popupSpy).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,18 @@ describe('UrlService Tests', () => {
});

describe('createAuthorizeUrl', () => {
it('returns null when no authoizationendpoint given -> wellKnownEndpoints null', () => {
it('returns empty string when no authoizationendpoint given -> wellKnownEndpoints null', () => {
const value = (service as any).createAuthorizeUrl(
'', // Implicit Flow
'https://localhost:44386',
'nonce',
'state'
);

const expectValue = null;

expect(value).toEqual(expectValue);
expect(value).toEqual('');
});

it('returns null when no authoizationendpoint given -> configurationProvider null', () => {
it('returns empty string when no authoizationendpoint given -> configurationProvider null', () => {
(service as any).configurationProvider = null;

const value = (service as any).createAuthorizeUrl(
Expand All @@ -188,12 +186,10 @@ describe('UrlService Tests', () => {
'state'
);

const expectValue = null;

expect(value).toEqual(expectValue);
expect(value).toEqual('');
});

it('returns null when clientId is null', () => {
it('returns empty string when clientId is null', () => {
const config = { configId: 'configId1', clientId: '' };
const authorizationEndpoint = 'authorizationEndpoint';

Expand All @@ -209,12 +205,10 @@ describe('UrlService Tests', () => {
config
);

const expectValue = null;

expect(value).toEqual(expectValue);
expect(value).toEqual('');
});

it('returns null when responseType is null', () => {
it('returns empty string when responseType is null', () => {
const config = {
configId: 'configId1',
clientId: 'something',
Expand All @@ -234,12 +228,10 @@ describe('UrlService Tests', () => {
config
);

const expectValue = null;

expect(value).toEqual(expectValue);
expect(value).toEqual('');
});

it('returns null when scope is null', () => {
it('returns empty string when scope is null', () => {
const config = {
configId: 'configId1',
clientId: 'something',
Expand All @@ -260,9 +252,7 @@ describe('UrlService Tests', () => {
config
);

const expectValue = null;

expect(value).toEqual(expectValue);
expect(value).toEqual('');
});

it('createAuthorizeUrl with code flow and codeChallenge adds "code_challenge" and "code_challenge_method" param', () => {
Expand Down Expand Up @@ -1561,7 +1551,7 @@ describe('UrlService Tests', () => {
const resultObs$ = serviceAsAny.createUrlCodeFlowWithSilentRenew(config);

resultObs$.subscribe((result: any) => {
expect(result).toBe(null);
expect(result).toBe('');
});
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export class UrlService {
configuration: OpenIdConfiguration,
prompt?: string,
customRequestParams?: { [key: string]: string | number | boolean }
): string | null {
): string {
const authWellKnownEndPoints = this.storagePersistenceService.read(
'authWellKnownEndPoints',
configuration
Expand All @@ -444,7 +444,7 @@ export class UrlService {
`Can not create an authorize URL when authorizationEndpoint is '${authorizationEndpoint}'`
);

return null;
return '';
}

const { clientId, responseType, scope, hdParam, customParamsAuthRequest } =
Expand All @@ -457,7 +457,7 @@ export class UrlService {
clientId
);

return null;
return '';
}

if (!responseType) {
Expand All @@ -467,7 +467,7 @@ export class UrlService {
responseType
);

return null;
return '';
}

if (!scope) {
Expand All @@ -477,7 +477,7 @@ export class UrlService {
scope
);

return null;
return '';
}

const urlParts = authorizationEndpoint.split('?');
Expand Down Expand Up @@ -564,7 +564,7 @@ export class UrlService {
private createUrlCodeFlowWithSilentRenew(
configuration: OpenIdConfiguration,
customParams?: { [key: string]: string | number | boolean }
): Observable<string | null> {
): Observable<string> {
const state =
this.flowsDataService.getExistingOrCreateAuthStateControl(configuration);
const nonce = this.flowsDataService.createNonce(configuration);
Expand All @@ -583,7 +583,7 @@ export class UrlService {
const silentRenewUrl = this.getSilentRenewUrl(configuration);

if (!silentRenewUrl) {
return null;
return '';
}

const authWellKnownEndPoints = this.storagePersistenceService.read(
Expand All @@ -608,7 +608,7 @@ export class UrlService {
'authWellKnownEndpoints is undefined'
);

return null;
return '';
})
);
}
Expand Down

0 comments on commit 33d69fa

Please sign in to comment.