@@ -11,6 +11,7 @@ import { _InternalLogMessage, DiagnosticLogger } from "../../../../src/diagnosti
1111import { ActiveStatus } from "../../../../src/enums/ai/InitActiveStatusEnum" ;
1212import { createAsyncPromise , createAsyncRejectedPromise , createAsyncResolvedPromise , createTimeoutPromise , doAwaitResponse } from "@nevware21/ts-async" ;
1313import { setBypassLazyCache } from "@nevware21/ts-utils" ;
14+ import { UrlRedactionOptions } from "../../../../src/enums/ai/UrlRedactionOptions"
1415
1516const AIInternalMessagePrefix = "AITR_" ;
1617const MaxInt32 = 0xFFFFFFFF ;
@@ -2073,7 +2074,6 @@ export class ApplicationInsightsCoreTests extends AITestClass {
20732074 test : ( ) => {
20742075 let config = {
20752076 redactUrls : false ,
2076- redactQueryParams : false ,
20772077 } as IConfiguration ;
20782078 const url = "https://username:password@example.com:8443/path/to/resource?sig=secret&color=blue#section2" ;
20792079 const redactedLocation = fieldRedaction ( url , config ) ;
@@ -2215,7 +2215,8 @@ export class ApplicationInsightsCoreTests extends AITestClass {
22152215 name : "FieldRedaction: should redact custom query parameters defined in redactQueryParams and replace custom queryParams" ,
22162216 test : ( ) => {
22172217 let config = {
2218- replaceRedactQueryParams : [ "authorize" , "api_key" , "password" ]
2218+ redactUrls : UrlRedactionOptions . replace ,
2219+ redactQueryParams : [ "authorize" , "api_key" , "password" ]
22192220 } as IConfiguration ;
22202221
22212222 const url = "https://example.com/path?auth_token=12345&name=test&authorize=secret" ;
@@ -2228,7 +2229,8 @@ export class ApplicationInsightsCoreTests extends AITestClass {
22282229 name : "FieldRedaction: should redact both default and custom query parameters" ,
22292230 test : ( ) => {
22302231 let config = {
2231- appendRedactQueryParams : [ "auth_token" ]
2232+ redactUrls : UrlRedactionOptions . append ,
2233+ redactQueryParams : [ "auth_token" ]
22322234 } as IConfiguration ;
22332235
22342236 const url = "https://example.com/path?sig=abc123&auth_token=12345&name=test" ;
@@ -2238,16 +2240,16 @@ export class ApplicationInsightsCoreTests extends AITestClass {
22382240 }
22392241 } ) ;
22402242 this . testCase ( {
2241- name : "FieldRedaction:should redact custom parameters when redactUrls is disabled but redactQueryParams is not false " ,
2243+ name : "FieldRedaction:should replace custom parameters redactQueryParams when user specifies the replace config " ,
22422244 test : ( ) => {
22432245 let config = {
2244- redactUrls : false ,
2245- replaceRedactQueryParams : [ "authorize" , "api_key" ]
2246+ redactUrls : UrlRedactionOptions . replace ,
2247+ redactQueryParams : [ "authorize" , "api_key" ]
22462248 } as IConfiguration ;
22472249
22482250 const url = "https://username:password@example.com/path?auth_token=12345&authorize=secret" ;
22492251 const redactedLocation = fieldRedaction ( url , config ) ;
2250- Assert . equal ( redactedLocation , "https://username:password @example.com/path?auth_token=12345&authorize=REDACTED" ,
2252+ Assert . equal ( redactedLocation , "https://REDACTED:REDACTED @example.com/path?auth_token=12345&authorize=REDACTED" ,
22512253 "URL with custom sensitive parameters should be redacted when query redaction is not disabled" ) ;
22522254 }
22532255 } ) ;
@@ -2269,7 +2271,8 @@ export class ApplicationInsightsCoreTests extends AITestClass {
22692271 name : "FieldRedaction:should handle complex URLs with both credentials and custom query parameters" ,
22702272 test : ( ) => {
22712273 let config = {
2272- appendRedactQueryParams : [ "authorize" , "session_id" ]
2274+ redactUrls : UrlRedactionOptions . append ,
2275+ redactQueryParams : [ "authorize" , "session_id" ]
22732276 } as IConfiguration ;
22742277
22752278 const url = "https://user:pass@example.com/path?sig=secret&authorize=abc123&visible=true&session_id=xyz789" ;
@@ -2601,7 +2604,7 @@ export class ApplicationInsightsCoreTests extends AITestClass {
26012604 name : "FieldRedaction: should redact credentials while preserving query strings when redactQueryParams is false" ,
26022605 test : ( ) => {
26032606 let config = {
2604- redactQueryParams : false
2607+ redactUrls : 5
26052608 } as IConfiguration ;
26062609 const url = "https://user:password@example.com/path?sig=secret&color=blue&token=abc123" ;
26072610 const redactedLocation = fieldRedaction ( url , config ) ;
@@ -2614,7 +2617,8 @@ export class ApplicationInsightsCoreTests extends AITestClass {
26142617 name : "FieldRedaction: should handle custom parameters with multiple occurrences and empty values" ,
26152618 test : ( ) => {
26162619 let config = {
2617- replaceRedactQueryParams : [ "auth_token" , "session_id" ]
2620+ redactUrls : UrlRedactionOptions . replace ,
2621+ redactQueryParams : [ "auth_token" , "session_id" ]
26182622 } as IConfiguration ;
26192623 const url = "https://example.com/path?auth_token=first&name=test&auth_token=&session_id=abc&session_id=" ;
26202624 const redactedLocation = fieldRedaction ( url , config ) ;
@@ -2638,24 +2642,23 @@ export class ApplicationInsightsCoreTests extends AITestClass {
26382642 } ) ;
26392643
26402644 this . testCase ( {
2641- name : "FieldRedaction: should preserve credentials while redacting query strings when redactUrls is false " ,
2645+ name : "FieldRedaction: should redact all parts of the URL (username, password, default query params) when redactUrls is set to True " ,
26422646 test : ( ) => {
26432647 let config = {
2644- redactUrls : false
2648+ redactUrls : true
26452649 } as IConfiguration ;
26462650 const url = "https://user:password@example.com/path?sig=secret&color=blue&token=abc123" ;
26472651 const redactedLocation = fieldRedaction ( url , config ) ;
2648- Assert . equal ( redactedLocation , "https://user:password @example.com/path?sig=REDACTED&color=blue&token=abc123" ,
2649- "Query string values should be redacted while credentials remain unchanged when redactUrls is false ") ;
2652+ Assert . equal ( redactedLocation , "https://REDACTED:REDACTED @example.com/path?sig=REDACTED&color=blue&token=abc123" ,
2653+ "All parts of the URL should be redacted when redactUrls is true ") ;
26502654 }
26512655 } ) ;
26522656
26532657 this . testCase ( {
26542658 name : "FieldRedaction: should not redact credentials or query strings when redactUrls and redactQueryParams are false" ,
26552659 test : ( ) => {
26562660 let config = {
2657- redactUrls : false ,
2658- redactQueryParams : false
2661+ redactUrls : UrlRedactionOptions . false
26592662 } as IConfiguration ;
26602663 const url = "https://user:password@example.com/path?sig=secret&color=blue&token=abc123" ;
26612664 const redactedLocation = fieldRedaction ( url , config ) ;
0 commit comments