Skip to content

Commit 4d5897b

Browse files
committed
Add_security_Azure_AD_B2C
1 parent 9050d02 commit 4d5897b

31 files changed

+444
-50
lines changed

.github/workflows/CD-time-tracker-ui.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,49 @@ name: CD process to deploy to App-Service service
55

66
on:
77
# Trigger the workflow on pull request but only for the master branch
8-
pull_request:
9-
types: [closed]
8+
# pull_request:
9+
# types: [closed]
10+
# branches:
11+
# - master
12+
# - add_security_azure_AD_B2C
13+
push:
1014
branches:
11-
- master
15+
- add_security_azure_AD_B2C
1216

1317
jobs:
1418
build-and-deploy:
1519
name: Deploy to Azure
1620
runs-on: ubuntu-latest
1721
timeout-minutes: 60
1822
steps:
19-
- name: Checkout of master
20-
uses: actions/checkout@master
23+
# - name: Checkout of master
24+
# uses: actions/checkout@master
2125

2226
- name: Set up Node.js version
2327
uses: actions/setup-node@v1
2428
with:
2529
node-version: '12.x'
2630

31+
- name: Inject Secrets
32+
shell: python
33+
env:
34+
SCOPES: ${{ secrets.scopes }}
35+
CLIENT_ID: ${{ secrets.client_id }}
36+
AUTHORITY: ${{ secrets.authority }}
37+
BASE_PATH: "src/environments/"
38+
run: |
39+
import os
40+
import json
41+
data = {}
42+
base_path = os.environ.get('BASE_PATH', 'src/environments/')
43+
with open(base_path + "keys.example.json", "r+") as jsonFileRead:
44+
data = json.load(jsonFileRead)
45+
data["scopes"] = str(os.environ['SCOPES']).split(",")
46+
data["client_id"] = os.environ['CLIENT_ID']
47+
data["authority"] = os.environ['AUTHORITY']
48+
with open(base_path + ".keys.json", "w+") as jsonFileWrite:
49+
json.dump(data, jsonFileWrite)
50+
2751
- name: 'run: npm install and build'
2852
run: |
2953
npm install

.github/workflows/CI-time-tracker-ui.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,25 @@ jobs:
3939
- name: Install dependencies
4040
run: npm install
4141

42+
- name: Inject Secrets
43+
shell: python
44+
env:
45+
SCOPES: ${{ secrets.scopes }}
46+
CLIENT_ID: ${{ secrets.client_id }}
47+
AUTHORITY: ${{ secrets.authority }}
48+
BASE_PATH: "src/environments/"
49+
run: |
50+
import os
51+
import json
52+
data = {}
53+
base_path = os.environ.get('BASE_PATH', 'src/environments/')
54+
with open(base_path + "keys.example.json", "r+") as jsonFileRead:
55+
data = json.load(jsonFileRead)
56+
data["scopes"] = str(os.environ['SCOPES']).split(",")
57+
data["client_id"] = os.environ['CLIENT_ID']
58+
data["authority"] = os.environ['AUTHORITY']
59+
with open(base_path + ".keys.json", "w+") as jsonFileWrite:
60+
json.dump(data, jsonFileWrite)
61+
4262
- name: Run the test
4363
run: npm run ci-test --if-present

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ npm-debug.log
4040
yarn-error.log
4141
testem.log
4242
/typings
43-
43+
.keys.json
4444
# System Files
4545
.DS_Store
4646
Thumbs.db

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Run `npm install -g @angular/cli` to install Angular CLI
1818

1919
Run `npm install` to install the required node_modules for this project.
2020

21+
Create file .keys.json from keys.example.ts into environments folder
22+
2123
## Development server
2224

2325
Run `ng serve` to run the app in dev mode. After executing this command, you can navigate to `http://localhost:4200/` to see the app working.

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"bootstrap": "^4.4.1",
2424
"jquery": "^3.4.1",
2525
"minimist": "^1.2.5",
26+
"msal": "^1.2.1",
2627
"rxjs": "~6.5.4",
2728
"tslib": "^1.10.0",
2829
"zone.js": "~0.10.2"

src/app/app-routing.module.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
4+
import { AzureGuardService } from './guards/azure-guard.service'
35
import { ReportsComponent } from './modules/reports/pages/reports.component';
46
import { TimeClockComponent } from './modules/time-clock/pages/time-clock.component';
57
import { TimeEntriesComponent } from './modules/time-entries/pages/time-entries.component';
68
import { ProjectManagementComponent } from './modules/project-management/pages/project-management.component';
79
import { ActivitiesManagementComponent } from './modules/activities-management/pages/activities-management.component';
10+
import { HomeComponent } from './modules/home/home.component';
11+
import { LoginComponent } from './modules/login/login.component';
812

913
const routes: Routes = [
10-
{path: 'reports', component: ReportsComponent},
11-
{path: 'time-clock', component: TimeClockComponent},
12-
{path: 'time-entries', component: TimeEntriesComponent},
13-
{path: 'project-management', component: ProjectManagementComponent},
14-
{path: 'activities-management', component: ActivitiesManagementComponent},
15-
{path: '', pathMatch: 'full', redirectTo: 'time-clock'},
16-
{path: '**', pathMatch: 'full', redirectTo: 'time-clock'},
14+
15+
{ path: '', component: HomeComponent, canActivate:[AzureGuardService],
16+
children: [
17+
{ path: 'reports', component: ReportsComponent },
18+
{ path: 'time-clock', component: TimeClockComponent },
19+
{ path: 'time-entries', component: TimeEntriesComponent },
20+
{ path: 'project-management', component: ProjectManagementComponent },
21+
{ path: 'activities-management', component: ActivitiesManagementComponent },
22+
{path: '', pathMatch: 'full', redirectTo: 'time-clock'},
23+
]
24+
},
25+
{ path: 'login', component: LoginComponent },
1726
];
1827

1928
@NgModule({

src/app/app.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<app-navbar></app-navbar>
2-
3-
<app-sidebar>
4-
<router-outlet></router-outlet>
5-
</app-sidebar>
1+
<router-outlet></router-outlet>

src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ActivitiesManagementComponent } from './modules/activities-management/p
2525
import { ActivityListComponent } from './modules/activities-management/components/activity-list/activity-list.component';
2626
import { CreateActivityComponent } from './modules/activities-management/components/create-activity/create-activity.component';
2727

28+
import { HomeComponent } from './modules/home/home.component';
29+
import { LoginComponent } from './modules/login/login.component';
2830

2931
@NgModule({
3032
declarations: [
@@ -47,7 +49,9 @@ import { CreateActivityComponent } from './modules/activities-management/compone
4749
GroupByDatePipe,
4850
ActivitiesManagementComponent,
4951
CreateActivityComponent,
50-
ActivityListComponent
52+
ActivityListComponent,
53+
HomeComponent,
54+
LoginComponent
5155
],
5256
imports: [
5357
CommonModule,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
3+
import { Router } from '@angular/router'
4+
5+
import { AzureAdB2CService } from '../modules/login/services/azure.ad.b2c.service';
6+
import { AzureGuardService } from './azure-guard.service';
7+
8+
9+
describe('AzureGuardService', () => {
10+
let service: AzureGuardService;
11+
let azureAdB2CService: AzureAdB2CService;
12+
const azureAdB2CServiceStub = {
13+
isLogin() {
14+
return true;
15+
}
16+
};
17+
beforeEach(() => {
18+
TestBed.configureTestingModule({
19+
imports: [ RouterTestingModule ],
20+
providers: [
21+
{ providers: AzureAdB2CService, useValue: azureAdB2CServiceStub},
22+
]
23+
});
24+
service = TestBed.inject(AzureGuardService);
25+
azureAdB2CService = TestBed.inject(AzureAdB2CService);
26+
});
27+
28+
it('should be created', () => {
29+
expect(service).toBeTruthy();
30+
});
31+
32+
it('should check if is login', () => {
33+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true)
34+
const isAcitve = service.canActivate();
35+
expect(azureAdB2CService.isLogin).toHaveBeenCalled;
36+
expect(isAcitve).toEqual(true);
37+
});
38+
39+
it('should check if not is login', inject([Router], (router: Router) => {
40+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false)
41+
spyOn(router, 'navigate').and.stub();
42+
const isAcitve = service.canActivate();
43+
expect(azureAdB2CService.isLogin).toHaveBeenCalled;
44+
expect(isAcitve).toEqual(false);
45+
expect(router.navigate).toHaveBeenCalledWith(['login']);
46+
}));
47+
48+
});

0 commit comments

Comments
 (0)