Repository: square/okhttp
File: okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.kt (Kotlin)

Code before:
    server.enqueue(
      MockResponse.Builder()
        .build(),
    )
    val response =
      client
        .newCall(
          request()
            .build(),
        )
        .execute()
    response.body.close()
    val sanitizedUrl = networkInterceptor.sanitizeUrl(url)
    val sanitizedUrlPattern = sanitizedUrl.replace("?", """\?""")
    applicationLogs
      .assertLogEqual("--> GET $sanitizedUrl")
      .assertLogMatch(Regex("""<-- 200 OK $sanitizedUrlPattern \(\d+ms, \d+-byte body\)"""))
      .assertNoMoreLogs()
    networkLogs
      .assertLogEqual("--> GET $sanitizedUrl http/1.1")
      .assertLogMatch(Regex("""<-- 200 OK $sanitizedUrlPattern \(\d+ms, \d+-byte body\)"""))
      .assertNoMoreLogs()
  }

  @Test
  fun preserveQueryParamsAfterSanitized() {
    url = server.url("""/api/login?
      |user=test_user&
      |authentication=basic&
      |password=confidential_password&
      |authentication=rather simple login method
    """.trimMargin())
    val networkInterceptor =
      HttpLoggingInterceptor(networkLogs).setLevel(
        Level.BASIC,
      )
    networkInterceptor.redactQueryParams("user", "passWord")

    val applicationInterceptor =
      HttpLoggingInterceptor(applicationLogs).setLevel(
        Level.BASIC,
      )
    applicationInterceptor.redactQueryParams("user", "PassworD")

    client =
      OkHttpClient.Builder()
        .addNetworkInterceptor(networkInterceptor)
        .addInterceptor(applicationInterceptor)
        .build()
    server.enqueue(
      MockResponse.Builder()

Review comment (suggestion):
Please use the word `Redacted` instead of `Sanitzed` throughout!

Code after:
        .build()
    server.enqueue(
      MockResponse.Builder()
        .build(),
    )
    val response =
      client
        .newCall(
          request()
            .build(),
        )
        .execute()
    response.body.close()
    val redactedUrl = networkInterceptor.redactUrl(url)
    val redactedUrlPattern = redactedUrl.replace("?", """\?""")
    applicationLogs
      .assertLogEqual("--> GET $redactedUrl")
      .assertLogMatch(Regex("""<-- 200 OK $redactedUrlPattern \(\d+ms, \d+-byte body\)"""))
      .assertNoMoreLogs()
    networkLogs
      .assertLogEqual("--> GET $redactedUrl http/1.1")
      .assertLogMatch(Regex("""<-- 200 OK $redactedUrlPattern \(\d+ms, \d+-byte body\)"""))
      .assertNoMoreLogs()
  }

  @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
  @Test
  fun preserveQueryParamsAfterRedacted() {
    url =
      server.url(
        """/api/login?
      |user=test_user&
      |authentication=basic&
      |password=confidential_password&
      |authentication=rather simple login method
        """.trimMargin(),
      )
    val networkInterceptor =
      HttpLoggingInterceptor(networkLogs).setLevel(
        Level.BASIC,
      )
    networkInterceptor.redactQueryParams("user", "passWord")

    val applicationInterceptor =
      HttpLoggingInterceptor(applicationLogs).setLevel(
        Level.BASIC,
      )
    applicationInterceptor.redactQueryParams("user", "PassworD")

    client =
      OkHttpClient.Builder()