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

chore: remove SecurityDetails API #35

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,10 @@
* [response.ok()](#responseok)
* [response.remoteAddress()](#responseremoteaddress)
* [response.request()](#responserequest)
* [response.securityDetails()](#responsesecuritydetails)
* [response.status()](#responsestatus)
* [response.statusText()](#responsestatustext)
* [response.text()](#responsetext)
* [response.url()](#responseurl)
- [class: SecurityDetails](#class-securitydetails)
* [securityDetails.issuer()](#securitydetailsissuer)
* [securityDetails.protocol()](#securitydetailsprotocol)
* [securityDetails.subjectName()](#securitydetailssubjectname)
* [securityDetails.validFrom()](#securitydetailsvalidfrom)
* [securityDetails.validTo()](#securitydetailsvalidto)
- [class: Target](#class-target)
* [target.browser()](#targetbrowser)
* [target.browserContext()](#targetbrowsercontext)
Expand Down Expand Up @@ -3802,9 +3795,6 @@ Contains a boolean stating whether the response was successful (status in the ra
#### response.request()
- returns: <[Request]> A matching [Request] object.

#### response.securityDetails()
- returns: <?[SecurityDetails]> Security details if the response was received over the secure connection, or `null` otherwise.

#### response.status()
- returns: <[number]>

Expand All @@ -3823,25 +3813,6 @@ Contains the status text of the response (e.g. usually an "OK" for a success).

Contains the URL of the response.

### class: SecurityDetails

[SecurityDetails] class represents the security details when response was received over the secure connection.

#### securityDetails.issuer()
- returns: <[string]> A string with the name of issuer of the certificate.

#### securityDetails.protocol()
- returns: <[string]> String with the security protocol, eg. "TLS 1.2".

#### securityDetails.subjectName()
- returns: <[string]> Name of the subject to which the certificate was issued to.

#### securityDetails.validFrom()
- returns: <[number]> [UnixTime] stating the start of validity of the certificate.

#### securityDetails.validTo()
- returns: <[number]> [UnixTime] stating the end of validity of the certificate.

### class: Target

#### target.browser()
Expand Down Expand Up @@ -4018,7 +3989,6 @@ TimeoutError is emitted whenever certain operations are terminated due to timeou
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
[Request]: #class-request "Request"
[Response]: #class-response "Response"
[SecurityDetails]: #class-securitydetails "SecurityDetails"
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
[Target]: #class-target "Target"
[TimeoutError]: #class-timeouterror "TimeoutError"
Expand Down
2 changes: 0 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export = {
Playwright: require('./chromium/Playwright').Playwright,
Request: require('./chromium/NetworkManager').Request,
Response: require('./chromium/NetworkManager').Response,
SecurityDetails: require('./chromium/NetworkManager').SecurityDetails,
Target: require('./chromium/Target').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./chromium/Input').Touchscreen,
Expand Down Expand Up @@ -65,7 +64,6 @@ export = {
Playwright: require('./firefox/Playwright').Playwright,
Request: require('./firefox/NetworkManager').Request,
Response: require('./firefox/NetworkManager').Response,
SecurityDetails: require('./firefox/NetworkManager').SecurityDetails,
Target: require('./firefox/Browser').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./firefox/Input').Touchscreen,
Expand Down
42 changes: 0 additions & 42 deletions src/chromium/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ export class Response {
private _statusText: string;
private _url: string;
private _headers: {[key: string]: string} = {};
private _securityDetails: SecurityDetails;

constructor(client: CDPSession, request: Request, responsePayload: Protocol.Network.Response) {
this._client = client;
Expand All @@ -460,7 +459,6 @@ export class Response {
this._url = request.url();
for (const key of Object.keys(responsePayload.headers))
this._headers[key.toLowerCase()] = responsePayload.headers[key];
this._securityDetails = responsePayload.securityDetails ? new SecurityDetails(responsePayload.securityDetails) : null;
}

remoteAddress(): { ip: string; port: number; } {
Expand All @@ -487,10 +485,6 @@ export class Response {
return this._headers;
}

securityDetails(): SecurityDetails | null {
return this._securityDetails;
}

buffer(): Promise<Buffer> {
if (!this._contentPromise) {
this._contentPromise = this._bodyLoadedPromise.then(async error => {
Expand Down Expand Up @@ -524,42 +518,6 @@ export class Response {
}
}

export class SecurityDetails {
private _subjectName: string;
private _issuer: string;
private _validFrom: number;
private _validTo: number;
private _protocol: string;

constructor(securityPayload: Protocol.Network.SecurityDetails) {
this._subjectName = securityPayload['subjectName'];
this._issuer = securityPayload['issuer'];
this._validFrom = securityPayload['validFrom'];
this._validTo = securityPayload['validTo'];
this._protocol = securityPayload['protocol'];
}

subjectName(): string {
return this._subjectName;
}

issuer(): string {
return this._issuer;
}

validFrom(): number {
return this._validFrom;
}

validTo(): number {
return this._validTo;
}

protocol(): string {
return this._protocol;
}
}

function headersArray(headers: { [s: string]: string; }): { name: string; value: string; }[] {
const result = [];
for (const name in headers) {
Expand Down
98 changes: 29 additions & 69 deletions src/firefox/NetworkManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {helper, assert, debugError} from '../helper';
import {EventEmitter} from 'events';
import { EventEmitter } from 'events';
import { assert, debugError, helper, RegisteredListener } from '../helper';
import { JugglerSession } from './Connection';
import { FrameManager } from './FrameManager';

Expand All @@ -12,10 +12,11 @@ export const NetworkManagerEvents = {

export class NetworkManager extends EventEmitter {
private _session: JugglerSession;
private _requests: Map<any, any>;
private _requests: Map<string, Request>;
private _frameManager: FrameManager;
private _eventListeners: any[];
constructor(session) {
private _eventListeners: RegisteredListener[];

constructor(session: JugglerSession) {
super();
this._session = session;

Expand Down Expand Up @@ -130,22 +131,21 @@ const causeToResourceType = {
};

export class Request {
_id(_id: any, request: Request) {
throw new Error('Method not implemented.');
}
_session: any;
_frame: any;
_id: string;
private _session: any;
private _frame: any;
_redirectChain: any;
_url: any;
_postData: any;
_suspended: any;
private _url: any;
private _postData: any;
private _suspended: any;
_response: any;
_errorText: any;
_isNavigationRequest: any;
_method: any;
_resourceType: any;
_headers: {};
_interceptionHandled: boolean;
private _isNavigationRequest: any;
private _method: any;
private _resourceType: any;
private _headers: {};
private _interceptionHandled: boolean;

constructor(session, frame, redirectChain, payload) {
this._session = session;
this._frame = frame;
Expand Down Expand Up @@ -236,17 +236,17 @@ export class Request {
}

export class Response {
_session: any;
_request: any;
_remoteIPAddress: any;
_remotePort: any;
_status: any;
_statusText: any;
_headers: {};
_securityDetails: SecurityDetails;
_bodyLoadedPromise: Promise<unknown>;
_bodyLoadedPromiseFulfill: (value?: unknown) => void;
_contentPromise: any;
private _session: any;
private _request: any;
private _remoteIPAddress: any;
private _remotePort: any;
private _status: any;
private _statusText: any;
private _headers: {};
private _bodyLoadedPromise: Promise<unknown>;
private _bodyLoadedPromiseFulfill: (value?: unknown) => void;
private _contentPromise: any;

constructor(session, request, payload) {
this._session = session;
this._request = request;
Expand All @@ -255,7 +255,6 @@ export class Response {
this._status = payload.status;
this._statusText = payload.statusText;
this._headers = {};
this._securityDetails = payload.securityDetails ? new SecurityDetails(payload.securityDetails) : null;
for (const {name, value} of payload.headers)
this._headers[name.toLowerCase()] = value;
this._bodyLoadedPromise = new Promise(fulfill => {
Expand Down Expand Up @@ -289,10 +288,6 @@ export class Response {
return JSON.parse(content);
}

securityDetails() {
return this._securityDetails;
}

headers() {
return {...this._headers};
}
Expand Down Expand Up @@ -328,38 +323,3 @@ export class Response {
return this._request;
}
}

export class SecurityDetails {
_subjectName: string;
_issuer: string;
_validFrom: number;
_validTo: number;
_protocol: string;
constructor(securityPayload: any) {
this._subjectName = securityPayload['subjectName'];
this._issuer = securityPayload['issuer'];
this._validFrom = securityPayload['validFrom'];
this._validTo = securityPayload['validTo'];
this._protocol = securityPayload['protocol'];
}

subjectName(): string {
return this._subjectName;
}

issuer(): string {
return this._issuer;
}

validFrom(): number {
return this._validFrom;
}

validTo(): number {
return this._validTo;
}

protocol(): string {
return this._protocol;
}
}
34 changes: 0 additions & 34 deletions test/ignorehttpserrors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,6 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
delete state.page;
});

describe('Response.securityDetails', function() {
it('should work', async({page, httpsServer}) => {
const [serverRequest, response] = await Promise.all([
httpsServer.waitForRequest('/empty.html'),
page.goto(httpsServer.EMPTY_PAGE)
]);
const securityDetails = response.securityDetails();
expect(securityDetails.issuer()).toBe('puppeteer-tests');
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(securityDetails.protocol()).toBe(protocol);
expect(securityDetails.subjectName()).toBe('puppeteer-tests');
expect(securityDetails.validFrom()).toBe(1550084863);
expect(securityDetails.validTo()).toBe(33086084863);
});
it('should be |null| for non-secure requests', async({page, server}) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.securityDetails()).toBe(null);
});
it('Network redirects should report SecurityDetails', async({page, httpsServer}) => {
httpsServer.setRedirect('/plzredirect', '/empty.html');
const responses = [];
page.on('response', response => responses.push(response));
const [serverRequest, ] = await Promise.all([
httpsServer.waitForRequest('/plzredirect'),
page.goto(httpsServer.PREFIX + '/plzredirect')
]);
expect(responses.length).toBe(2);
expect(responses[0].status()).toBe(302);
const securityDetails = responses[0].securityDetails();
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(securityDetails.protocol()).toBe(protocol);
});
});

it('should work', async({page, httpsServer}) => {
let error = null;
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
Expand Down
3 changes: 0 additions & 3 deletions test/launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
]);
expect(error).toBe(null);
expect(response.ok()).toBe(true);
expect(response.securityDetails()).toBeTruthy();
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(response.securityDetails().protocol()).toBe(protocol);
await page.close();
await browser.close();
});
Expand Down