Skip to content

Commit

Permalink
Merge branch '4.1' into sw-backport-4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Nov 4, 2021
2 parents 39a1b01 + 9f236d6 commit 3698e63
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 325 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 4.1.1

### Fixes

[#74](https://github.com/okta/okta-angular/pull/74) Fixes old version angular compatibility issue

# 4.1.0

### Features
Expand Down
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@
"tslib": "^1.9.0"
},
"devDependencies": {
"@angular/animations": "11.2.10",
"@angular/cli": "11.2.9",
"@angular/common": "11.2.10",
"@angular/compiler": "11.2.10",
"@angular/compiler-cli": "11.2.10",
"@angular/core": "11.2.10",
"@angular/platform-browser": "11.2.10",
"@angular/platform-browser-dynamic": "11.2.10",
"@angular/platform-server": "11.2.10",
"@angular/router": "11.2.10",
"@compodoc/compodoc": "^1.1.11",
"@angular/animations": "7.2.16",
"@angular/common": "7.2.16",
"@angular/compiler": "7.2.16",
"@angular/compiler-cli": "7.2.16",
"@angular/core": "7.2.16",
"@angular/platform-browser": "7.2.16",
"@angular/platform-browser-dynamic": "7.2.16",
"@angular/platform-server": "7.2.16",
"@angular/router": "7.2.16",
"@compodoc/compodoc": "1.1.9",
"@rollup/plugin-commonjs": "11.0.1",
"@rollup/plugin-node-resolve": "7.0.0",
"@types/jest": "^26.0.14",
Expand Down Expand Up @@ -92,14 +91,14 @@
"ts-loader": "^9.0.2",
"tsickle": "^0.39.1",
"tslint": "^6.1.3",
"typescript": "~4.0.7",
"typescript": "~3.2.0",
"uglify-js": "3.13.5",
"webpack": "^4.32.2",
"webpack-filter-warnings-plugin": "1.2.1",
"zone.js": "~0.10.3"
"zone.js": "~0.8.26"
},
"peerDependencies": {
"@okta/okta-auth-js": "^5.4.2"
"@okta/okta-auth-js": "^5.4.3"
},
"jest": {
"coverageDirectory": "<rootDir>/test-reports/coverage",
Expand Down
4 changes: 2 additions & 2 deletions src/okta/okta.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class OktaAuthGuard implements CanActivate, CanActivateChild, CanLoad {
}

async canLoad(route: Route, segments: UrlSegment[]): Promise<boolean> {
this.onAuthRequired = route.data?.onAuthRequired || this.onAuthRequired;
this.onAuthRequired = route.data && route.data.onAuthRequired || this.onAuthRequired;

const isAuthenticated = await this.oktaAuth.isAuthenticated();
if (isAuthenticated) {
Expand All @@ -74,7 +74,7 @@ export class OktaAuthGuard implements CanActivate, CanActivateChild, CanLoad {
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
// Track states for current route
this.state = state;
this.onAuthRequired = route.data?.onAuthRequired || this.onAuthRequired;
this.onAuthRequired = route.data && route.data.onAuthRequired || this.onAuthRequired;

// Protect the route after accessing
this.oktaAuth.authStateManager.subscribe(this.updateAuthStateListener);
Expand Down
2 changes: 1 addition & 1 deletion src/okta/okta.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class OktaAuthModule {

// Auth-js version compatibility runtime check
const oktaAuthVersion = oktaAuth._oktaUserAgent.getVersion();
const majorVersion = +oktaAuthVersion?.split('.')[0];
const majorVersion = +oktaAuthVersion.split('.')[0];
if (packageInfo.authJSMajorVersion !== majorVersion) {
throw new AuthSdkError(`Passed in oktaAuth is not compatible with the SDK, okta-auth-js version ${packageInfo.authJSMajorVersion}.x is the current supported version.`);
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@okta/okta-angular": "*",
"@okta/okta-auth-js": "^5.4.2",
"@okta/okta-auth-js": "^5.4.3",
"@angular/animations": "~11.2.10",
"@angular/common": "~11.2.10",
"@angular/compiler": "~11.2.10",
Expand Down
62 changes: 31 additions & 31 deletions test/spec/auth-state.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('OktaAuthStateService', () => {
it('should be created and subscribe to authState change', () => {
jest.spyOn(oktaAuth.authStateManager, 'subscribe');
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
expect(service).toBeTruthy();
expect(service.authState$).toBeInstanceOf(Observable);
expect(oktaAuth.authStateManager.subscribe).toHaveBeenCalled();
Expand All @@ -44,37 +44,37 @@ describe('OktaAuthStateService', () => {
const mockState = { mock: 'mock' } as unknown as AuthState;
jest.spyOn(oktaAuth.authStateManager, 'getAuthState').mockReturnValue(mockState);
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
return new Promise(resolve => {
service.authState$.subscribe(authState => {
expect(authState).toBe(mockState);
resolve(null);
resolve(undefined);
});
});
});

it('initials with default authState when oktaAuth state is not ready', () => {
jest.spyOn(oktaAuth.authStateManager, 'getAuthState').mockReturnValue(null as unknown as AuthState);
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
return new Promise(resolve => {
service.authState$.subscribe(authState => {
expect(authState).toEqual({ isAuthenticated: false });
resolve(null);
resolve(undefined);
});
});
});

it('updates with oktaAuth state changes', () => {
const states = [{ mock1: 'mock1' }, { mock2: 'mock2' }];
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
const fn = jest.fn();
return new Promise(resolve => {
let calls = 0;
service.authState$.subscribe(authState => {
if (++calls === 3) {
resolve(null);
resolve(undefined);
}
fn(authState);
});
Expand All @@ -91,11 +91,11 @@ describe('OktaAuthStateService', () => {
it('observes false result', () => {
jest.spyOn(oktaAuth.authStateManager, 'getAuthState').mockReturnValue({ isAuthenticated: false } as AuthState);
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
return new Promise(resolve => {
service.hasAnyGroups(['mock']).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -105,11 +105,11 @@ describe('OktaAuthStateService', () => {
it('observes false result', () => {
jest.spyOn(oktaAuth.authStateManager, 'getAuthState').mockReturnValue({ idToken: undefined } as AuthState);
setup(oktaAuth);
const service: OktaAuthStateService = TestBed.inject(OktaAuthStateService);
const service: OktaAuthStateService = TestBed.get(OktaAuthStateService);
return new Promise(resolve => {
service.hasAnyGroups(['mock']).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -129,23 +129,23 @@ describe('OktaAuthStateService', () => {
}
} as unknown as AuthState);
setup(oktaAuth);
service = TestBed.inject(OktaAuthStateService);
service = TestBed.get(OktaAuthStateService);
});

describe('can verify with string input', () => {
it('observes true when groups match', () => {
return new Promise(resolve => {
service.hasAnyGroups('test').subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups('non-exist-group').subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -155,15 +155,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups(['test']).subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups(['non-exist-group']).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -173,15 +173,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups({ groups: ['test'] }).subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups({ groups: ['non-exist-group'] }).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -204,22 +204,22 @@ describe('OktaAuthStateService', () => {
'custom-groups': ['test']
} as unknown as UserClaims);
setup(oktaAuth);
service = TestBed.inject(OktaAuthStateService);
service = TestBed.get(OktaAuthStateService);
});
describe('can verify with object input', () => {
it('observes true when groups match', () => {
return new Promise(resolve => {
service.hasAnyGroups({ 'custom-groups': ['test'] }).subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups({ 'custom-groups': ['non-exist-group'] }).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -228,15 +228,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups(['test']).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
it('fails with string input', () => {
return new Promise(resolve => {
service.hasAnyGroups('test').subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -256,14 +256,14 @@ describe('OktaAuthStateService', () => {
groups: ['test']
} as unknown as UserClaims);
setup(oktaAuth);
service = TestBed.inject(OktaAuthStateService);
service = TestBed.get(OktaAuthStateService);
});

it('calls oktaAuth.getUser()', () => {
return new Promise(resolve => {
service.hasAnyGroups('test').subscribe(() => {
expect(oktaAuth.getUser).toHaveBeenCalled();
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -273,15 +273,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups('test').subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups('non-exist-group').subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -291,15 +291,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups(['test']).subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups(['non-exist-group']).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand All @@ -309,15 +309,15 @@ describe('OktaAuthStateService', () => {
return new Promise(resolve => {
service.hasAnyGroups({ groups: ['test'] }).subscribe(result => {
expect(result).toEqual(true);
resolve(null);
resolve(undefined);
});
});
});
it('observes false when groups not match', () => {
return new Promise(resolve => {
service.hasAnyGroups({ groups: ['non-exist-group'] }).subscribe(result => {
expect(result).toEqual(false);
resolve(null);
resolve(undefined);
});
});
});
Expand Down
Loading

0 comments on commit 3698e63

Please sign in to comment.