debug-key.sub.https.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!doctype html>
  2. <meta charset=utf-8>
  3. <meta name=timeout content=long>
  4. <meta name=variant content="?include=source">
  5. <meta name=variant content="?include=trigger">
  6. <script src="/resources/testharness.js"></script>
  7. <script src="/resources/testharnessreport.js"></script>
  8. <script src="/common/subset-tests-by-key.js"></script>
  9. <script src="resources/helpers.js"></script>
  10. <script>
  11. const debug_key_promise_test = (testCase, forSource) =>
  12. attribution_reporting_promise_test(async t => {
  13. await registerAttributionSrc(t, {
  14. source: {
  15. destination: `https://{{host}}`,
  16. debug_key: forSource ? testCase.debugKey : undefined,
  17. },
  18. cookie: testCase.cookie,
  19. });
  20. await registerAttributionSrc(t, {trigger: {
  21. event_trigger_data: [{trigger_data: '0'}],
  22. debug_key: forSource ? undefined : testCase.debugKey,
  23. }});
  24. const payload = await pollEventLevelReports();
  25. assert_equals(payload.reports.length, 1);
  26. const report = JSON.parse(payload.reports[0].body);
  27. let keyUnderTest = 'trigger_debug_key';
  28. let otherKey = 'source_debug_key';
  29. if (forSource) {
  30. [keyUnderTest, otherKey] = [otherKey, keyUnderTest];
  31. }
  32. if (testCase.keyExpected) {
  33. assert_equals(report[keyUnderTest], testCase.debugKey);
  34. } else {
  35. assert_not_own_property(report, keyUnderTest);
  36. }
  37. assert_not_own_property(report, otherKey);
  38. }, testCase.testName);
  39. [
  40. {
  41. testName: 'Valid cookie propagates debug key.',
  42. debugKey: '246',
  43. cookie: 'ar_debug=1;Secure;HttpOnly;SameSite=None;Path=/',
  44. keyExpected: true,
  45. },
  46. {
  47. testName: 'Missing cookie clears debug key.',
  48. debugKey: '246',
  49. cookie: 'foo=1;Secure;HttpOnly;SameSite=None;Path=/',
  50. keyExpected: false,
  51. },
  52. {
  53. testName: 'Cookie without Secure clears debug key.',
  54. debugKey: '246',
  55. cookie: 'ar_debug=1;HttpOnly;SameSite=None;Path=/',
  56. keyExpected: false,
  57. },
  58. {
  59. testName: 'Cookie without HttpOnly clears debug key.',
  60. debugKey: '246',
  61. cookie: 'ar_debug=1;Secure;SameSite=None;Path=/',
  62. keyExpected: false,
  63. },
  64. {
  65. testName: 'Cookie without SameSite=None clears debug key.',
  66. debugKey: '246',
  67. cookie: 'ar_debug=1;Secure;HttpOnly;Path=/',
  68. keyExpected: false,
  69. },
  70. {
  71. testName: 'Cookie with narrow Path clears debug key.',
  72. debugKey: '246',
  73. cookie: 'ar_debug=1;Secure;HttpOnly;SameSite=None',
  74. keyExpected: false,
  75. },
  76. {
  77. testName: 'Field with wrong type is ignored.',
  78. debugKey: 246,
  79. cookie: 'ar_debug=1;Secure;HttpOnly;SameSite=None;Path=/',
  80. keyExpected: false,
  81. },
  82. {
  83. testName: 'Field with invalid format is ignored.',
  84. debugKey: '-246',
  85. cookie: 'ar_debug=1;Secure;HttpOnly;SameSite=None;Path=/',
  86. keyExpected: false,
  87. },
  88. ].forEach(testCase => {
  89. subsetTestByKey('source', debug_key_promise_test, testCase, /*forSource=*/true);
  90. subsetTestByKey('trigger', debug_key_promise_test, testCase, /*forSource=*/false);
  91. });
  92. </script>