Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPv2 Add the ability to inspect a cert/DS #7555

Merged
merged 16 commits into from
Jul 31, 2023
3 changes: 2 additions & 1 deletion experimental/traffic-portal/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"allowedCommonJsDependencies": [
"chart.js"
"chart.js",
"node-forge"
],
"customWebpackConfig": {
"path": "src/compress-webpack.config.js"
Expand Down
24 changes: 21 additions & 3 deletions experimental/traffic-portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions experimental/traffic-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"chart.js": "^2.9.4",
"compression-webpack-plugin": "^10.0.0",
"express": "^4.15.2",
"node-forge": "^1.3.1",
"rxjs": "~6.6.0",
"trafficops-types": "^4.0.10",
"tslib": "^2.0.0",
Expand All @@ -90,6 +91,7 @@
"@types/jasminewd2": "~2.0.3",
"@types/nightwatch": "^2.3.22",
"@types/node": "^16.18.11",
"@types/node-forge": "^1.3.2",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"axios": "^0.27.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
import { TestBed } from "@angular/core/testing";
import { DSStats, DSStatsMetricType } from "trafficops-types";
import { DSStats, DSStatsMetricType, ResponseDeliveryServiceSSLKey } from "trafficops-types";

import { constructDataSetFromResponse, DeliveryServiceService } from "./delivery-service.service";

Expand Down Expand Up @@ -96,6 +96,15 @@ export const testDS = {
xmlId: "testquest",
};

/** A dummy DS SSL Key for testing */
export const testDSSSLKeys: ResponseDeliveryServiceSSLKey = {
cdn: testDS.cdnName,
certificate: {crt: "", csr: "", key: ""},
deliveryservice: testDS.xmlId,
expiration: new Date(),
version: ""
};

/**
* Generates a basic set of DSStats data for use in tests.
*
Expand Down Expand Up @@ -369,7 +378,7 @@ describe("DeliveryServiceService", () => {
expect(req.request.method).toBe("GET");

const metricType = req.request.params.get("metricType");
switch(metricType) {
switch (metricType) {
case "tps_total":
req.flush({response: totalResponse});
break;
Expand Down Expand Up @@ -416,32 +425,34 @@ describe("DeliveryServiceService", () => {
expect(req.request.params.get("endDate")).toBe(now.toISOString());
expect(req.request.method).toBe("GET");

req.flush({response: {
series: {
columns: ["time", "mean"],
count: 0,
name: "invalid",
values: [
[
twoSecondsAgo,
null
req.flush({
response: {
series: {
columns: ["time", "mean"],
count: 0,
name: "invalid",
values: [
[
twoSecondsAgo,
null
],
[
now,
0
]
],
[
now,
0
]
],
},
summary: {
average: 1,
count: 2,
fifthPercentile: 3,
max: 4,
min: 5,
ninetyEightPercentile: 6,
ninetyFifthPercentile: 7
},
summary: {
average: 1,
count: 2,
fifthPercentile: 3,
max: 4,
min: 5,
ninetyEightPercentile: 6,
ninetyFifthPercentile: 7
}
}
}});
});
}

await expectAsync(responseP).toBeRejected();
Expand Down Expand Up @@ -570,6 +581,28 @@ describe("DeliveryServiceService", () => {
await expectAsync(responseP).toBeResolvedTo(response);
});

it("gets DS ssl keys", async () => {
let resp = service.getSSLKeys(testDS.xmlId);
let req = httpTestingController.expectOne(r => r.url ===
`/api/${service.apiVersion}/deliveryservices/xmlId/${testDS.xmlId}/sslkeys`);
expect(req.request.params.keys().length).toBe(1);
expect(req.request.params.get("decode")).toBe("true");
expect(req.request.method).toBe("GET");
req.flush({response: testDSSSLKeys});

await expectAsync(resp).toBeResolvedTo(testDSSSLKeys);

resp = service.getSSLKeys(testDS);
req = httpTestingController.expectOne(r => r.url ===
`/api/${service.apiVersion}/deliveryservices/xmlId/${testDS.xmlId}/sslkeys`);
expect(req.request.params.keys().length).toBe(1);
expect(req.request.params.get("decode")).toBe("true");
expect(req.request.method).toBe("GET");
req.flush({response: testDSSSLKeys});

await expectAsync(resp).toBeResolvedTo(testDSSSLKeys);
});

afterEach(() => {
httpTestingController.verify();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import type {
RequestDeliveryService,
ResponseDeliveryService,
SteeringConfiguration,
TypeFromResponse
TypeFromResponse,
ResponseDeliveryServiceSSLKey
} from "trafficops-types";

import type {
Expand Down Expand Up @@ -441,4 +442,16 @@ export class DeliveryServiceService extends APIService {
this.deliveryServiceTypes = r;
return r;
}

/**
* Gets a Delivery Service's SSL Keys
*
* @param ds The delivery service xmlid or object
* @returns The DS ssl keys
*/
public async getSSLKeys(ds: string | ResponseDeliveryService): Promise<ResponseDeliveryServiceSSLKey> {
const xmlId = typeof ds === "string" ? ds : ds.xmlId;
shamrickus marked this conversation as resolved.
Show resolved Hide resolved
const path = `deliveryservices/xmlId/${xmlId}/sslkeys`;
return this.get<ResponseDeliveryServiceSSLKey>(path, undefined, {decode: true}).toPromise();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Health,
RequestDeliveryService,
ResponseDeliveryService,
ResponseDeliveryServiceSSLKey,
SteeringConfiguration,
TypeFromResponse
} from "trafficops-types";
Expand Down Expand Up @@ -171,6 +172,13 @@
useInTable: "deliveryservice"
}
];
private readonly dsSSLKeys: Array<ResponseDeliveryServiceSSLKey> = [{
cdn: "'",
certificate: {crt: "", csr: "", key: ""},
deliveryservice: "xml",
expiration: new Date(),
version: ""
}];

constructor(
private readonly cdnService: CDNService,
Expand Down Expand Up @@ -536,4 +544,20 @@
public async getDSTypes(): Promise<Array<TypeFromResponse>> {
return this.dsTypes;
}

/**
* Gets a Delivery Service's SSL Keys
*
* @param ds The delivery service xmlid or object
* @returns The DS ssl keys
*/
public async getSSLKeys(ds: string | ResponseDeliveryService): Promise<ResponseDeliveryServiceSSLKey> {

Check warning on line 554 in experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts

View check run for this annotation

Codecov / codecov/patch

experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts#L554

Added line #L554 was not covered by tests
const xmlId = typeof ds === "string" ? ds : ds.xmlId;
const key = this.dsSSLKeys.find(k => k.deliveryservice === xmlId);

Check warning on line 556 in experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts

View check run for this annotation

Codecov / codecov/patch

experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts#L556

Added line #L556 was not covered by tests
if(!key) {
throw new Error(`no such Delivery Service: ${xmlId}`);

Check warning on line 558 in experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts

View check run for this annotation

Codecov / codecov/patch

experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts#L558

Added line #L558 was not covered by tests
}

return key;

Check warning on line 561 in experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts

View check run for this annotation

Codecov / codecov/patch

experimental/traffic-portal/src/app/api/testing/delivery-service.service.ts#L561

Added line #L561 was not covered by tests
}
}
2 changes: 2 additions & 0 deletions experimental/traffic-portal/src/app/app.ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { MatSidenavModule } from "@angular/material/sidenav";
import { MatSlideToggleModule } from "@angular/material/slide-toggle";
import { MatSnackBarModule } from "@angular/material/snack-bar";
import { MatStepperModule } from "@angular/material/stepper";
import { MatTabsModule } from "@angular/material/tabs";
import { MatToolbarModule } from "@angular/material/toolbar";
import { MatTooltipModule } from "@angular/material/tooltip";
import { MatTreeModule } from "@angular/material/tree";
Expand Down Expand Up @@ -74,6 +75,7 @@ import { AgGridModule } from "ag-grid-angular";
MatSidenavModule,
MatSnackBarModule,
MatStepperModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
MatTreeModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div *ngIf="author" class="content">
<mat-form-field>
<mat-label>Common Name</mat-label>
<input matInput type="text" name="commonName" readonly [value]="author.commonName"/>
</mat-form-field>
<div class="triple">
<mat-form-field>
<mat-label>Country Name</mat-label>
<input matInput type="text" name="country" readonly [value]="author.countryName ?? ''"/>
</mat-form-field>
<mat-form-field>
<mat-label>State or Province</mat-label>
<input matInput type="text" name="state" readonly [value]="author.stateOrProvince ?? ''"/>
</mat-form-field>
<mat-form-field>
<mat-label>Locality</mat-label>
<input matInput type="text" name="local" readonly [value]="author.localityName ?? ''"/>
</mat-form-field>
</div>
<mat-form-field>
<mat-label>Organization</mat-label>
<input matInput type="text" name="org" readonly [value]="author.orgName ?? ''"/>
</mat-form-field>
<mat-form-field>
<mat-label>Organization Unit</mat-label>
<input matInput type="text" name="org" readonly [value]="author.orgUnit ?? ''"/>
</mat-form-field>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
div.content {
display: grid;

.triple {
display: grid;
grid-template-columns: 1fr 2fr 2fr;
grid-column-gap: 10px;
}
}
Loading
Loading