Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2017-02-19 21:28:37 +0000
committerThomas Wolf2017-03-01 19:43:28 +0000
commit4bc15e7f9023024b9e1c803d185ed16730218931 (patch)
tree8a7d449e251ebfbdfea5f7ede7b57d176e2402de /org.eclipse.egit.ui.test/src
parent7ac21ccc9faf0ff5fe9952391e311491f6952c53 (diff)
downloadegit-4bc15e7f9023024b9e1c803d185ed16730218931.tar.gz
egit-4bc15e7f9023024b9e1c803d185ed16730218931.tar.xz
egit-4bc15e7f9023024b9e1c803d185ed16730218931.zip
Prevent creation of invalid git config keys
Allow only alphanumeric characters and the dash in git config section and variable names. Subsections get quoted and may contain other characters. Extend the validation in AddConfigEntryDialog to prevent the accidental creation of invalid git config entries; those would break all git, JGit, and EGit functionality and the only way to fix this would be to edit the offending git config file manually in a text editor. With an invalid git config file, not even "git config --help" works! Change-Id: I65a3279069639d44922da8c8792a27b9aa51fe4e Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java77
1 files changed, 62 insertions, 15 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
index 794caa12f1..5b8be0678c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
@@ -12,6 +12,7 @@ package org.eclipse.egit.ui.prefpages.configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.util.ArrayList;
@@ -251,29 +252,75 @@ public class GlobalConfigurationPageTest {
SWTBotShell addDialog = bot
.shell(UIText.AddConfigEntryDialog_AddConfigTitle);
addDialog.activate();
- // neither key nor value set
- assertTrue(!addDialog.bot().button(IDialogConstants.OK_LABEL)
- .isEnabled());
+ assertFalse("Should be disabled when neither key nor value set",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_ValueLabel)
.setText("Somevalue");
- // key empty
- assertTrue(!addDialog.bot().button(IDialogConstants.OK_LABEL)
- .isEnabled());
+ assertFalse("Should be disabled when no key",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
.setText(TESTSECTION);
- // no dot
- assertTrue(!addDialog.bot().button(IDialogConstants.OK_LABEL)
- .isEnabled());
+ assertFalse("Should be disabled when no dot",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
.setText(TESTSECTION + "." + TESTNAME);
- // ok: one dot
- assertTrue(addDialog.bot().button(IDialogConstants.OK_LABEL)
- .isEnabled());
+ assertTrue("Should be enabled with one dot",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
.setText(TESTSECTION + "." + TESTSUBSECTION + "." + TESTNAME);
- // ok: two dots
- assertTrue(addDialog.bot().button(IDialogConstants.OK_LABEL)
- .isEnabled());
+ assertTrue("Should be enabled with two dots",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText(TESTSECTION
+ + ". some stuff with dots.. and . non-ASCII characters: àéè."
+ + TESTNAME);
+ // ok: first and last section alphanumeric,subsection will be quoted
+ assertTrue("Should be enabled with strange subsection",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("föö.bar.baz");
+ assertFalse("Should be disabled with non-ASCII in first segment",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foo.bar.bàz");
+ assertFalse("Should be disabled with non-ASCII in last segment",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foo bar.baz");
+ assertFalse("Should be disabled with blank in first segment",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foo.bar baz");
+ assertFalse("Should be disabled with blank in last segment",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foo-bar.baz-");
+ assertTrue("Should be enabled with dashes",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foo.bar.");
+ assertFalse("Should be disabled when ending in dot",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText(".foo.bar.");
+ assertFalse("Should be disabled when beginning with dot",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("..");
+ assertFalse("Should be disabled for \"..\"",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foobar.9nines");
+ assertFalse("Should be disabled for variable name starting with digit",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foobar.-bar");
+ assertFalse("Should be disabled for variable name starting with a dash",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
+ addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel)
+ .setText("foobar.b-9");
+ assertTrue("Should be enabled for variable name starting with a letter",
+ addDialog.bot().button(IDialogConstants.OK_LABEL).isEnabled());
}
@Test

Back to the top