1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.android.libraries.mobiledatadownload.file.backends; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.net.Uri; 21 import com.google.thirdparty.robolectric.GoogleRobolectricTestRunner; 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 25 /** Test {@link com.google.android.libraries.mobiledatadownload.file.backends.UriNormalizer}. */ 26 @RunWith(GoogleRobolectricTestRunner.class) 27 public final class UriNormalizerTest { 28 29 @Test normalizeUriWithDotDot()30 public void normalizeUriWithDotDot() { 31 Uri uri = Uri.parse("android://package/files/common/../shared/path/.."); 32 33 assertThat(UriNormalizer.normalizeUri(uri).toString()) 34 .isEqualTo("android://package/files/shared"); 35 } 36 37 @Test normalizeUriWithDot()38 public void normalizeUriWithDot() { 39 Uri uri = Uri.parse("android://package/files/common/./shared/path/././."); 40 41 assertThat(UriNormalizer.normalizeUri(uri).toString()) 42 .isEqualTo("android://package/files/common/shared/path"); 43 } 44 45 @Test normalizeUriWithSlashSlash()46 public void normalizeUriWithSlashSlash() { 47 Uri uri = Uri.parse("android://package/files/common//shared/path//"); 48 49 assertThat(UriNormalizer.normalizeUri(uri).toString()) 50 .isEqualTo("android://package/files/common/shared/path"); 51 } 52 53 @Test normalizeUriWithUppercaseScheme()54 public void normalizeUriWithUppercaseScheme() { 55 Uri uri = Uri.parse("ANDROID://package/files/common/shared/path"); 56 57 assertThat(UriNormalizer.normalizeUri(uri).toString()) 58 .isEqualTo("android://package/files/common/shared/path"); 59 } 60 61 @Test normalizeUriReachesEndOfPath()62 public void normalizeUriReachesEndOfPath() { 63 Uri uri = Uri.parse("android://package/files/common/shared/path/../../../../../.."); 64 65 assertThat(UriNormalizer.normalizeUri(uri).toString()).isEqualTo("android://package/"); 66 } 67 } 68