diff options
author | Harald Musum <musum@yahooinc.com> | 2022-04-27 09:44:54 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-04-27 09:44:54 +0200 |
commit | 90402e33fe73f74e38f77d6a1ddc5b892aaf03f2 (patch) | |
tree | ae9ff8d0fc6568ec1eaa34c667077e860dcffdc0 /config-application-package/src/test | |
parent | e45cd30a0cf9e99be02af029dbb5c8517ba8ce4b (diff) |
Validate file extension for files in application package
Start validating file extension for files application package subdirectories,
only a subset of subdirectories handled for now
Diffstat (limited to 'config-application-package/src/test')
7 files changed, 65 insertions, 1 deletions
diff --git a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java index fd5437c27de..bea7efb40f4 100644 --- a/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/model/application/provider/FilesApplicationPackageTest.java @@ -105,7 +105,7 @@ public class FilesApplicationPackageTest { } @Test - public void testLegacyOverrides() throws IOException { + public void testLegacyOverrides() { File appDir = new File("src/test/resources/app-legacy-overrides"); ApplicationPackage app = FilesApplicationPackage.fromFile(appDir); var overrides = app.legacyOverrides(); @@ -143,4 +143,25 @@ public class FilesApplicationPackageTest { .getMessage()); } + @Test + public void testValidFileExtensions() { + File appDir = new File("src/test/resources/app-with-deployment");; + FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); + app.validateFileExtensions(true); + } + + @Test + public void testInvalidFileExtensions() { + File appDir = new File("src/test/resources/app-with-invalid-files-in-subdir");; + FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); + try { + app.validateFileExtensions(true); + fail("expected an exception"); + } catch (IllegalArgumentException e) { + assertEquals("File in application package with unknown suffix: search/query-profiles/file-with-invalid.extension " + + "Please delete or move file to another directory.", + e.getMessage()); + } + } + } diff --git a/config-application-package/src/test/resources/app-with-deployment/search/query-profiles/default.xml b/config-application-package/src/test/resources/app-with-deployment/search/query-profiles/default.xml new file mode 100644 index 00000000000..6e3069d8f96 --- /dev/null +++ b/config-application-package/src/test/resources/app-with-deployment/search/query-profiles/default.xml @@ -0,0 +1,4 @@ +<query-profile id="default"> + <field name="maxHits">30000</field> + <field name="maxOffset">30000</field> +</query-profile> diff --git a/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/deployment.xml b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/deployment.xml new file mode 100644 index 00000000000..3aad0ca6a6a --- /dev/null +++ b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/deployment.xml @@ -0,0 +1,9 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<deployment version='1.0'> + <test /> + <staging /> + <prod> + <region active="true">us-east</region> + <region active="false">us-west-1</region> + </prod> +</deployment> diff --git a/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/hosts.xml b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/hosts.xml new file mode 100644 index 00000000000..64a07644038 --- /dev/null +++ b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/hosts.xml @@ -0,0 +1,10 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<hosts xmlns:deploy="vespa" xmlns:preprocess="properties"> + <preprocess:properties> + <node1.hostname>foo.yahoo.com</node1.hostname> + <node1.hostname deploy:environment="dev">bar.yahoo.com</node1.hostname> + </preprocess:properties> + <host name="${node1.hostname}"> + <alias>node1</alias> + </host> +</hosts> diff --git a/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/schemas/music.sd b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/schemas/music.sd new file mode 100644 index 00000000000..7da7c49c162 --- /dev/null +++ b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/schemas/music.sd @@ -0,0 +1,8 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +search music { + document music { + field f type string { + indexing: index | summary + } + } +} diff --git a/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/search/query-profiles/file-with-invalid.extension b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/search/query-profiles/file-with-invalid.extension new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/search/query-profiles/file-with-invalid.extension diff --git a/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/services.xml b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/services.xml new file mode 100644 index 00000000000..60d08cb615c --- /dev/null +++ b/config-application-package/src/test/resources/app-with-invalid-files-in-subdir/services.xml @@ -0,0 +1,12 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version='1.0'> + <admin version='2.0'> + <adminserver hostalias='node0'/> + </admin> + <content version='1.0' id='foo'> + <redundancy>1</redundancy> + <documents> + <document type="music.sd" mode="index" /> + </documents> + </content> +</services> |