From 653b4b9df3845acf0e80f3fadb7fe346189a813c Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 20 Nov 2019 13:53:27 -0800 Subject: [PATCH] chore: remove SecurityDetails API (#35) --- docs/api.md | 30 ----------- src/api.ts | 2 - src/chromium/NetworkManager.ts | 42 --------------- src/firefox/NetworkManager.ts | 98 ++++++++++------------------------ test/ignorehttpserrors.spec.js | 34 ------------ test/launcher.spec.js | 3 -- 6 files changed, 29 insertions(+), 180 deletions(-) diff --git a/docs/api.md b/docs/api.md index 1f2ed56683314..136d6ecd51170 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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) @@ -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: Security details if the response was received over the secure connection, or `null` otherwise. - #### response.status() - returns: <[number]> @@ -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() @@ -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" diff --git a/src/api.ts b/src/api.ts index a3a4a1346dbc0..6f9d3218eb9cb 100644 --- a/src/api.ts +++ b/src/api.ts @@ -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, @@ -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, diff --git a/src/chromium/NetworkManager.ts b/src/chromium/NetworkManager.ts index 82fb05a1e471f..5c87f2676b229 100644 --- a/src/chromium/NetworkManager.ts +++ b/src/chromium/NetworkManager.ts @@ -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; @@ -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; } { @@ -487,10 +485,6 @@ export class Response { return this._headers; } - securityDetails(): SecurityDetails | null { - return this._securityDetails; - } - buffer(): Promise { if (!this._contentPromise) { this._contentPromise = this._bodyLoadedPromise.then(async error => { @@ -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) { diff --git a/src/firefox/NetworkManager.ts b/src/firefox/NetworkManager.ts index d7dccb4f5ab8c..13fb242e2d343 100644 --- a/src/firefox/NetworkManager.ts +++ b/src/firefox/NetworkManager.ts @@ -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'; @@ -12,10 +12,11 @@ export const NetworkManagerEvents = { export class NetworkManager extends EventEmitter { private _session: JugglerSession; - private _requests: Map; + private _requests: Map; private _frameManager: FrameManager; - private _eventListeners: any[]; - constructor(session) { + private _eventListeners: RegisteredListener[]; + + constructor(session: JugglerSession) { super(); this._session = session; @@ -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; @@ -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; - _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; + private _bodyLoadedPromiseFulfill: (value?: unknown) => void; + private _contentPromise: any; + constructor(session, request, payload) { this._session = session; this._request = request; @@ -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 => { @@ -289,10 +288,6 @@ export class Response { return JSON.parse(content); } - securityDetails() { - return this._securityDetails; - } - headers() { return {...this._headers}; } @@ -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; - } -} diff --git a/test/ignorehttpserrors.spec.js b/test/ignorehttpserrors.spec.js index b440b6ee5203d..0dec0f178f9db 100644 --- a/test/ignorehttpserrors.spec.js +++ b/test/ignorehttpserrors.spec.js @@ -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); diff --git a/test/launcher.spec.js b/test/launcher.spec.js index 354ac61c53819..0ca0f0cef1ef2 100644 --- a/test/launcher.spec.js +++ b/test/launcher.spec.js @@ -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(); });