Skip to content

Commit 012fb4c

Browse files
committed
Merge branch 'main' into feature/integration-proxy
2 parents ef78d75 + 90077ba commit 012fb4c

File tree

4 files changed

+505
-497
lines changed

4 files changed

+505
-497
lines changed

crates/common/src/html_processor.rs

Lines changed: 0 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -367,111 +367,6 @@ mod tests {
367367
}
368368
}
369369

370-
fn config_from_settings(
371-
settings: &Settings,
372-
registry: &IntegrationRegistry,
373-
) -> HtmlProcessorConfig {
374-
HtmlProcessorConfig::from_settings(
375-
settings,
376-
registry,
377-
"origin.example.com",
378-
"test.example.com",
379-
"https",
380-
)
381-
}
382-
383-
#[test]
384-
fn test_always_injects_tsjs_script() {
385-
let html = r#"<html><head>
386-
<script src="/js/prebid.min.js"></script>
387-
<link rel="preload" as="script" href="https://cdn.prebid.org/prebid.js" />
388-
</head><body></body></html>"#;
389-
390-
let mut settings = create_test_settings();
391-
settings
392-
.integrations
393-
.insert_config(
394-
"prebid",
395-
&json!({
396-
"enabled": true,
397-
"server_url": "https://test-prebid.com/openrtb2/auction",
398-
"timeout_ms": 1000,
399-
"bidders": ["mocktioneer"],
400-
"auto_configure": false,
401-
"debug": false
402-
}),
403-
)
404-
.expect("should update prebid config");
405-
let registry = IntegrationRegistry::new(&settings);
406-
let config = config_from_settings(&settings, &registry);
407-
let processor = create_html_processor(config);
408-
let pipeline_config = PipelineConfig {
409-
input_compression: Compression::None,
410-
output_compression: Compression::None,
411-
chunk_size: 8192,
412-
};
413-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
414-
415-
let mut output = Vec::new();
416-
let result = pipeline.process(Cursor::new(html.as_bytes()), &mut output);
417-
assert!(result.is_ok());
418-
let processed = String::from_utf8_lossy(&output);
419-
// When auto-configure is disabled, do not rewrite Prebid references
420-
assert!(processed.contains("/js/prebid.min.js"));
421-
assert!(processed.contains("cdn.prebid.org/prebid.js"));
422-
assert!(processed.contains("tsjs-unified"));
423-
}
424-
425-
#[test]
426-
fn prebid_auto_config_removes_prebid_scripts() {
427-
let html = r#"<html><head>
428-
<script src="https://cdn.prebid.org/prebid.min.js"></script>
429-
<link rel="preload" as="script" href="https://cdn.prebid.org/prebid.js" />
430-
</head><body></body></html>"#;
431-
432-
let mut settings = create_test_settings();
433-
settings
434-
.integrations
435-
.insert_config(
436-
"prebid",
437-
&json!({
438-
"enabled": true,
439-
"server_url": "https://test-prebid.com/openrtb2/auction",
440-
"timeout_ms": 1000,
441-
"bidders": ["mocktioneer"],
442-
"auto_configure": true,
443-
"debug": false
444-
}),
445-
)
446-
.expect("should update prebid config");
447-
let registry = IntegrationRegistry::new(&settings);
448-
let config = config_from_settings(&settings, &registry);
449-
let processor = create_html_processor(config);
450-
let pipeline_config = PipelineConfig {
451-
input_compression: Compression::None,
452-
output_compression: Compression::None,
453-
chunk_size: 8192,
454-
};
455-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
456-
457-
let mut output = Vec::new();
458-
let result = pipeline.process(Cursor::new(html.as_bytes()), &mut output);
459-
assert!(result.is_ok());
460-
let processed = String::from_utf8_lossy(&output);
461-
assert!(
462-
processed.contains("tsjs-unified"),
463-
"Unified bundle should be injected"
464-
);
465-
assert!(
466-
!processed.contains("prebid.min.js"),
467-
"Prebid script should be removed"
468-
);
469-
assert!(
470-
!processed.contains("cdn.prebid.org/prebid.js"),
471-
"Prebid preload should be removed"
472-
);
473-
}
474-
475370
#[test]
476371
fn integration_attribute_rewriter_can_remove_elements() {
477372
struct RemovingLinkRewriter;
@@ -526,157 +421,6 @@ mod tests {
526421
assert!(!processed.contains("remove-me"));
527422
}
528423

529-
#[test]
530-
fn test_rewrites_nextjs_script_when_enabled() {
531-
let html = r#"<html><body>
532-
<script id="__NEXT_DATA__" type="application/json">
533-
{"props":{"pageProps":{"primary":{"href":"https://origin.example.com/reviews"},"secondary":{"href":"http://origin.example.com/sign-in"},"fallbackHref":"http://origin.example.com/legacy","protoRelative":"//origin.example.com/assets/logo.png"}}}
534-
</script>
535-
</body></html>"#;
536-
537-
let mut settings = create_test_settings();
538-
settings
539-
.integrations
540-
.insert_config(
541-
"nextjs",
542-
&json!({
543-
"enabled": true,
544-
"rewrite_attributes": ["href", "link", "url"],
545-
}),
546-
)
547-
.expect("should update nextjs config");
548-
let registry = IntegrationRegistry::new(&settings);
549-
let config = config_from_settings(&settings, &registry);
550-
let processor = create_html_processor(config);
551-
let pipeline_config = PipelineConfig {
552-
input_compression: Compression::None,
553-
output_compression: Compression::None,
554-
chunk_size: 8192,
555-
};
556-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
557-
558-
let mut output = Vec::new();
559-
pipeline
560-
.process(Cursor::new(html.as_bytes()), &mut output)
561-
.unwrap();
562-
let processed = String::from_utf8_lossy(&output);
563-
println!("processed={processed}");
564-
println!("processed stream payload: {}", processed);
565-
println!("processed stream payload: {}", processed);
566-
567-
assert!(
568-
processed.contains(r#""href":"https://test.example.com/reviews""#),
569-
"Should rewrite https Next.js href values"
570-
);
571-
assert!(
572-
processed.contains(r#""href":"https://test.example.com/sign-in""#),
573-
"Should rewrite http Next.js href values"
574-
);
575-
assert!(
576-
processed.contains(r#""fallbackHref":"http://origin.example.com/legacy""#),
577-
"Should leave other fields untouched"
578-
);
579-
assert!(
580-
processed.contains(r#""protoRelative":"//origin.example.com/assets/logo.png""#),
581-
"Should not rewrite non-href keys"
582-
);
583-
assert!(
584-
!processed.contains("\"href\":\"https://origin.example.com/reviews\""),
585-
"Should remove origin https href"
586-
);
587-
assert!(
588-
!processed.contains("\"href\":\"http://origin.example.com/sign-in\""),
589-
"Should remove origin http href"
590-
);
591-
}
592-
593-
#[test]
594-
fn test_rewrites_nextjs_stream_payload() {
595-
let html = r#"<html><body>
596-
<script>
597-
self.__next_f.push([1,"chunk", "prefix {\"inner\":\"value\"} \\\"href\\\":\\\"http://origin.example.com/dashboard\\\", \\\"link\\\":\\\"https://origin.example.com/api-test\\\" suffix", {"href":"http://origin.example.com/secondary","dataHost":"https://origin.example.com/api"}]);
598-
</script>
599-
</body></html>"#;
600-
601-
let mut settings = create_test_settings();
602-
settings
603-
.integrations
604-
.insert_config(
605-
"nextjs",
606-
&json!({
607-
"enabled": true,
608-
"rewrite_attributes": ["href", "link", "url"],
609-
}),
610-
)
611-
.expect("should update nextjs config");
612-
let registry = IntegrationRegistry::new(&settings);
613-
let config = config_from_settings(&settings, &registry);
614-
let processor = create_html_processor(config);
615-
let pipeline_config = PipelineConfig {
616-
input_compression: Compression::None,
617-
output_compression: Compression::None,
618-
chunk_size: 8192,
619-
};
620-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
621-
622-
let mut output = Vec::new();
623-
pipeline
624-
.process(Cursor::new(html.as_bytes()), &mut output)
625-
.unwrap();
626-
let processed = String::from_utf8_lossy(&output);
627-
let normalized = processed.replace('\\', "");
628-
assert!(
629-
normalized.contains("\"href\":\"https://test.example.com/dashboard\""),
630-
"Should rewrite escaped href sequences inside streamed payloads. Content: {}",
631-
normalized
632-
);
633-
assert!(
634-
normalized.contains("\"href\":\"https://test.example.com/secondary\""),
635-
"Should rewrite plain href attributes inside streamed payloads"
636-
);
637-
assert!(
638-
normalized.contains("\"link\":\"https://test.example.com/api-test\""),
639-
"Should rewrite additional configured attributes like link"
640-
);
641-
assert!(
642-
processed.contains("\"dataHost\":\"https://origin.example.com/api\""),
643-
"Should leave non-href properties untouched"
644-
);
645-
}
646-
647-
#[test]
648-
fn test_nextjs_rewrite_respects_flag() {
649-
let html = r#"<html><body>
650-
<script id="__NEXT_DATA__" type="application/json">
651-
{"props":{"pageProps":{"href":"https://origin.example.com/reviews"}}}
652-
</script>
653-
</body></html>"#;
654-
655-
let config = create_test_config();
656-
let processor = create_html_processor(config);
657-
let pipeline_config = PipelineConfig {
658-
input_compression: Compression::None,
659-
output_compression: Compression::None,
660-
chunk_size: 8192,
661-
};
662-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
663-
664-
let mut output = Vec::new();
665-
pipeline
666-
.process(Cursor::new(html.as_bytes()), &mut output)
667-
.unwrap();
668-
let processed = String::from_utf8_lossy(&output);
669-
670-
assert!(
671-
processed.contains("origin.example.com"),
672-
"Should leave Next.js data untouched when disabled"
673-
);
674-
assert!(
675-
!processed.contains("test.example.com/reviews"),
676-
"Should not rewrite Next.js data when flag is off"
677-
);
678-
}
679-
680424
#[test]
681425
fn test_create_html_processor_url_replacement() {
682426
let config = create_test_config();

0 commit comments

Comments
 (0)