-
Notifications
You must be signed in to change notification settings - Fork 48
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
Implement Fallback for Blocked demdex.net Requests #1215
Open
shammowla
wants to merge
8
commits into
main
Choose a base branch
from
PDCL-8332
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−81
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da5d6eb
Implement fallback when demdex.net is blocked.
shammowla cb9c19f
Remove warning logs used during dev.
shammowla 715a382
Ensure element is added to DOM before test runs.
shammowla a9397f5
Use Testcafe Request Mock instead of modifying the on-page fetch.
shammowla 6ee2fd6
Make TypeError and NetworkError constants and make an utility metod.
shammowla 379b689
Revert "[skip ci] update self devDependency to 2.24.0"
shammowla 640a88c
Revert changes to demdex fallback changes.
shammowla 9f3db89
Fallback to regular collection when demdex.net is blocked.
shammowla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you 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 REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
export const TYPE_ERROR = "TypeError"; | ||
export const NETWORK_ERROR = "NetworkError"; | ||
|
||
/** | ||
* Checks if the error is a network-related error | ||
* @param {Error} error The error to check | ||
* @returns {boolean} True if the error is network-related | ||
*/ | ||
export const isNetworkError = (error) => { | ||
return ( | ||
error.name === TYPE_ERROR || | ||
error.name === NETWORK_ERROR || | ||
error.status === 0 | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you 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 REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import { RequestMock } from "testcafe"; | ||
|
||
// Mock that fails demdex requests | ||
export default RequestMock() | ||
.onRequestTo((request) => request.url.includes("demdex.net")) | ||
.respond((req, res) => { | ||
res.statusCode = 500; | ||
res.headers = { | ||
"content-type": "application/json", | ||
}; | ||
return ""; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you 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 REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import { t } from "testcafe"; | ||
import createNetworkLogger from "../../helpers/networkLogger/index.js"; | ||
import createFixture from "../../helpers/createFixture/index.js"; | ||
import { | ||
compose, | ||
orgMainConfigMain, | ||
thirdPartyCookiesEnabled, | ||
} from "../../helpers/constants/configParts/index.js"; | ||
import createAlloyProxy from "../../helpers/createAlloyProxy.js"; | ||
import demdexBlockerMock from "../../helpers/requestHooks/demdexBlockerMock.js"; | ||
|
||
const networkLogger = createNetworkLogger(); | ||
const config = compose(orgMainConfigMain, thirdPartyCookiesEnabled); | ||
|
||
createFixture({ | ||
title: "Demdex Fallback Behavior", | ||
requestHooks: [networkLogger.edgeEndpointLogs, demdexBlockerMock], | ||
}); | ||
|
||
test("Continues collecting data when demdex is blocked", async () => { | ||
const alloy = createAlloyProxy(); | ||
|
||
await alloy.configure(config); | ||
await alloy.sendEvent(); | ||
|
||
// Get all requests | ||
const requests = networkLogger.edgeEndpointLogs.requests; | ||
|
||
// Find the successful request (should be the last one) | ||
const successfulRequest = requests[requests.length - 1]; | ||
|
||
// Verify the successful request | ||
await t.expect(successfulRequest.request.url).notContains("demdex.net"); | ||
await t.expect(successfulRequest.request.url).contains(config.edgeDomain); | ||
await t.expect(successfulRequest.response.statusCode).eql(200); | ||
|
||
// Verify at least one request was successful | ||
const successfulRequests = requests.filter( | ||
(r) => | ||
!r.request.url.includes("demdex.net") && r.response.statusCode === 200, | ||
); | ||
await t.expect(successfulRequests.length).gte(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
TYPE_ERROR, | ||
NETWORK_ERROR, | ||
isNetworkError, | ||
} from "../../../../src/utils/networkErrors.js"; | ||
|
||
describe("Network Errors", () => { | ||
describe("isNetworkError", () => { | ||
it("returns true for TypeError", () => { | ||
const error = new Error(); | ||
error.name = TYPE_ERROR; | ||
|
||
expect(isNetworkError(error)).toBe(true); | ||
}); | ||
|
||
it("returns true for NetworkError", () => { | ||
const error = new Error(); | ||
error.name = NETWORK_ERROR; | ||
|
||
expect(isNetworkError(error)).toBe(true); | ||
}); | ||
|
||
it("returns true for status 0", () => { | ||
const error = { status: 0 }; | ||
|
||
expect(isNetworkError(error)).toBe(true); | ||
}); | ||
|
||
it("returns false for other errors", () => { | ||
const error = new Error(); | ||
error.name = "SyntaxError"; | ||
|
||
expect(isNetworkError(error)).toBe(false); | ||
}); | ||
|
||
it("returns false for non-zero status", () => { | ||
const error = { status: 500 }; | ||
|
||
expect(isNetworkError(error)).toBe(false); | ||
}); | ||
|
||
it("returns false for undefined status", () => { | ||
const error = new Error(); | ||
|
||
expect(isNetworkError(error)).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these comments?