Skip to content

Commit

Permalink
Resolve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
feifeiji89 committed Sep 16, 2024
1 parent abe4b3c commit 243d4a1
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 22 deletions.
6 changes: 3 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ An attribution source is a [=struct=] with the following items:
:: A non-negative integer.
: <dfn>remaining aggregatable attribution bucket budget</dfn>
:: A [=map=] whose [=map/key|keys=] are [=strings=] and whose [=map/value|values=] are
non-negative integers.
positive integers.
: <dfn>aggregatable dedup keys</dfn>
:: A [=set=] of [=aggregatable dedup key/dedup key|aggregatable dedup key values=] associated with this [=attribution source=].
: <dfn>debug reporting enabled</dfn>
Expand Down Expand Up @@ -3683,7 +3683,7 @@ To <dfn>parse aggregatable buckets</dfn> given a [=map=] |map|:
:: |filterPair|[0]
: [=aggregatable bucket/negated filters=]
:: |filterPair|[1]
1. [=set/Append=] |aggregatableBucket| to |aggregatableBuckets|.
1. [=list/Append=] |aggregatableBucket| to |aggregatableBuckets|.
1. Return |aggregatableBuckets|.

To <dfn>parse attribution scopes for trigger</dfn> from a [=map=] |map|:
Expand Down Expand Up @@ -3972,7 +3972,7 @@ To <dfn>find matching aggregatable bucket</dfn> given an [=attribution trigger=]
To <dfn>get remaining aggregatable budget for matched bucket</dfn> given an [=attribution trigger=] |trigger| and an [=attribution source=] |sourceToAttribute|:
1. Let |matchedBucket| be the result of running [=find matching aggregatable bucket=] with |trigger| and |sourceToAttribute|.
1. [=Assert=]: |matchedBucket| is not null.
1. If |sourceToAttribute|'s [=attribution source/remaining aggregatable attribution bucket budget=][|matchedBucket|] does not [=map/exists|exist=]
1. If |sourceToAttribute|'s [=attribution source/remaining aggregatable attribution bucket budget=][|matchedBucket|] does not [=map/exists|exist=]:
1. Return [=allowed aggregatable budget per source=].
1. Return |sourceToAttribute|'s [=attribution source/remaining aggregatable attribution bucket budget=][|matchedBucket|].

Expand Down
1 change: 1 addition & 0 deletions ts/src/header-validator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ <h1>Attribution Reporting Header Validation</h1>
<p><label><input type=radio name=header value=info><code>Attribution-Reporting-Info</code></label>
<p><label><input type=checkbox checked disabled>Use Chromium's vendor-specific values</label> <a href="https://github.com/WICG/attribution-reporting-api/blob/main/params/chromium-params.md" target=_blank>(details)</a>
<p><label><input type=checkbox name=flex>Enable experimental Flexible Event fields</label> <a href="https://github.com/WICG/attribution-reporting-api/blob/main/flexible_event_config.md" target=_blank>(details)</a>
<p><label><input type=checkbox name=aggregatableBucket>Enable experimental Aggregatable Bucket fields</label> <a href="https://github.com/WICG/attribution-reporting-api/issues/1396" target=_blank>(details)</a>
</fieldset>
<fieldset id=output>
<legend>Validation Result</legend>
Expand Down
9 changes: 9 additions & 0 deletions ts/src/header-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const sourceTypeFieldset =
const effective = document.querySelector('#effective')!

const flexCheckbox = form.elements.namedItem('flex') as HTMLInputElement
const aggregatableBucketCheckbox = form.elements.namedItem(
'aggregatableBucket'
) as HTMLInputElement

function sourceType(): SourceType {
return parseSourceType(sourceTypeRadios.value)
Expand All @@ -31,17 +34,20 @@ function sourceType(): SourceType {
function validate(): void {
sourceTypeFieldset.disabled = true
flexCheckbox.disabled = true
aggregatableBucketCheckbox.disabled = true

let v: validator.Validator<unknown>

switch (headerRadios.value) {
case 'source':
sourceTypeFieldset.disabled = false
flexCheckbox.disabled = false
aggregatableBucketCheckbox.disabled = false
v = source.validator({
vsv: vsv.Chromium,
sourceType: sourceType(),
fullFlex: flexCheckbox.checked,
aggregatableBucket: aggregatableBucketCheckbox.checked,
noteInfoGain: true,
})
break
Expand All @@ -50,6 +56,7 @@ function validate(): void {
v = trigger.validator({
vsv: vsv.Chromium,
fullFlex: flexCheckbox.checked,
aggregatableBucket: aggregatableBucketCheckbox.checked,
})
break
case 'os-source':
Expand Down Expand Up @@ -100,6 +107,7 @@ document.querySelector('#linkify')!.addEventListener('click', () => {
}

url.searchParams.set('flex', flexCheckbox.checked.toString())
url.searchParams.set('aggregatableBucket', flexCheckbox.checked.toString())

void navigator.clipboard.writeText(url.toString())
})
Expand Down Expand Up @@ -137,5 +145,6 @@ if (st !== null && st in SourceType) {
sourceTypeRadios.value = st

flexCheckbox.checked = params.get('flex') === 'true'
aggregatableBucketCheckbox.checked = params.get('aggregatableBucket') === 'true'

validate()
8 changes: 8 additions & 0 deletions ts/src/header-validator/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Arguments {
file?: string

fullFlex: boolean
aggregatableBucket: boolean
sourceType?: SourceType

silent: boolean
Expand Down Expand Up @@ -48,6 +49,11 @@ const options = parse<Arguments>(
description: 'If true, parse experimental Full Flexible Event fields.',
},

aggregatableBucket: {
type: Boolean,
description: 'If true, parse experimental Aggregatable Bucket fields.',
},

silent: {
type: Boolean,
description: 'If true, suppress output.',
Expand Down Expand Up @@ -95,10 +101,12 @@ const out = validate<unknown>(
? trigger.validator({
vsv: vsv.Chromium,
fullFlex: options.fullFlex,
aggregatableBucket: options.aggregatableBucket,
})
: source.validator({
vsv: vsv.Chromium,
fullFlex: options.fullFlex,
aggregatableBucket: options.aggregatableBucket,
sourceType: options.sourceType,
})
)
Expand Down
17 changes: 13 additions & 4 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ const testCases: TestCase[] = [
"max_event_states": 4
},
"aggregatable_bucket_max_budget": {
"firebase": 32768,
"third_party": 32768
"1": 32768,
"2": 32768
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expected: Maybe.some({
aggregatableReportWindow: 3601,
aggregationKeys: new Map([['a', 15n]]),
Expand Down Expand Up @@ -100,8 +101,8 @@ const testCases: TestCase[] = [
maxEventStates: 4,
},
aggregatableBucketBudget: new Map([
['firebase', 32768],
['third_party', 32768],
['1', 32768],
['2', 32768],
]),
}),
},
Expand Down Expand Up @@ -3082,6 +3083,7 @@ const testCases: TestCase[] = [
"aggregatable_bucket_max_budget": ["1"]
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'must be an object',
Expand All @@ -3098,6 +3100,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'bucket exceeds max length per aggregatable bucket (51 > 50)',
Expand All @@ -3117,6 +3120,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
},
{
name: 'aggregatable-buckets-too-many',
Expand Down Expand Up @@ -3147,6 +3151,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'exceeds the maximum number of keys (20)',
Expand All @@ -3165,6 +3170,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'must be in the range [1, 65536]',
Expand All @@ -3185,6 +3191,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'must be in the range [1, 65536]',
Expand All @@ -3201,6 +3208,7 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseAggregatableBucket: true,
expectedErrors: [
{
msg: 'must be a number',
Expand All @@ -3218,6 +3226,7 @@ testCases.forEach((tc) =>
sourceType: tc.sourceType ?? SourceType.navigation,
fullFlex: tc.parseFullFlex,
noteInfoGain: tc.noteInfoGain,
aggregatableBucket: tc.parseAggregatableBucket,
})
)
)
14 changes: 7 additions & 7 deletions ts/src/header-validator/to-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type Source = CommonDebug &

export interface Options {
fullFlex?: boolean | undefined
aggregatableBucket?: boolean | undefined
}

export function serializeSource(
Expand Down Expand Up @@ -247,9 +248,9 @@ export function serializeSource(
...ifNotNull('attribution_scopes', s.attributionScopes, (v) =>
serializeAttributionScopes(v)
),
aggregatable_bucket_max_budget: Object.fromEntries(
s.aggregatableBucketBudget
),
aggregatable_bucket_max_budget: opts.aggregatableBucket
? Object.fromEntries(s.aggregatableBucketBudget)
: {},
}

return stringify(source)
Expand Down Expand Up @@ -411,10 +412,9 @@ export function serializeTrigger(
serializeAggregatableDedupKey
),

aggregatable_buckets: Array.from(
t.aggregatableBuckets,
serializeAggregatableBucket
),
aggregatable_buckets: opts.aggregatableBucket
? Array.from(t.aggregatableBuckets, serializeAggregatableBucket)
: [],

aggregatable_source_registration_time: t.aggregatableSourceRegistrationTime,

Expand Down
7 changes: 7 additions & 0 deletions ts/src/header-validator/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
},
"attribution_scopes": ["1"]
}`,
parseAggregatableBucket: true,
expected: Maybe.some({
aggregatableDedupKeys: [
{
Expand Down Expand Up @@ -1743,6 +1744,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
{
name: 'aggregatable-buckets-wrong-type',
input: `{"aggregatable_buckets": 1}`,
parseAggregatableBucket: true,
expectedErrors: [
{
path: ['aggregatable_buckets'],
Expand All @@ -1753,6 +1755,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
{
name: 'aggregatable-buckets-value-wrong-type',
input: `{"aggregatable_buckets": [1]}`,
parseAggregatableBucket: true,
expectedErrors: [
{
path: ['aggregatable_buckets', 0],
Expand All @@ -1765,6 +1768,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
input: `{"aggregatable_buckets": [{
"bucket": 1
}]}`,
parseAggregatableBucket: true,
expectedErrors: [
{
path: ['aggregatable_buckets', 0, 'bucket'],
Expand All @@ -1778,6 +1782,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
"filters": [],
"not_filters": []
}]}`,
parseAggregatableBucket: true,
expectedErrors: [
{
path: ['aggregatable_buckets', 0, 'bucket'],
Expand All @@ -1792,6 +1797,7 @@ const testCases: jsontest.TestCase<Trigger>[] = [
"filters": [],
"not_filters": []
}]}`,
parseAggregatableBucket: true,
},
]

Expand All @@ -1801,6 +1807,7 @@ testCases.forEach((tc) =>
trigger.validator({
vsv: { ...vsv.Chromium, ...tc.vsv },
fullFlex: tc.parseFullFlex,
aggregatableBucket: tc.parseAggregatableBucket,
})
)
)
1 change: 1 addition & 0 deletions ts/src/header-validator/validate-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import * as vsv from '../vendor-specific-values'
export type TestCase<T> = testutil.TestCase<T> & {
vsv?: Readonly<Partial<vsv.VendorSpecificValues>>
parseFullFlex?: boolean
parseAggregatableBucket?: boolean
}
1 change: 1 addition & 0 deletions ts/src/header-validator/validate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const UINT32_MAX: number = 2 ** 32 - 1
export interface RegistrationOptions {
vsv: VendorSpecificValues
fullFlex?: boolean | undefined
aggregatableBucket?: boolean | undefined
}

export class RegistrationContext<
Expand Down
10 changes: 6 additions & 4 deletions ts/src/header-validator/validate-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,12 @@ function source(j: Json, ctx: Context): Maybe<Source> {
'attribution_scopes',
withDefault(attributionScopes, null)
),
aggregatableBucketBudget: field(
'aggregatable_bucket_max_budget',
withDefault(aggregatableBucketBudget, new Map())
),
aggregatableBucketBudget: ctx.opts.aggregatableBucket
? field(
'aggregatable_bucket_max_budget',
withDefault(aggregatableBucketBudget, new Map())
)
: () => Maybe.some(new Map()),

...commonDebugFields,
...priorityField,
Expand Down
7 changes: 3 additions & 4 deletions ts/src/header-validator/validate-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,9 @@ function trigger(j: Json, ctx: Context): Maybe<Trigger> {
'aggregatable_deduplication_keys',
withDefault(aggregatableDedupKeys, [])
),
aggregatableBuckets: field(
'aggregatable_buckets',
withDefault(aggregatableBuckets, [])
),
aggregatableBuckets: ctx.opts.aggregatableBucket
? field('aggregatable_buckets', withDefault(aggregatableBuckets, []))
: () => Maybe.some([]),
aggregatableSourceRegistrationTime: () => aggregatableSourceRegTimeVal,
eventTriggerData: field(
'event_trigger_data',
Expand Down

0 comments on commit 243d4a1

Please sign in to comment.