Skip to content

Commit ab6022a

Browse files
authored
Do handle legacy as well (#79)
It detects it, but decrypt did not handle them
1 parent 54f7dd7 commit ab6022a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher
133133

134134
@Override
135135
public String decrypt(String str) throws SecDispatcherException, IOException {
136-
if (!isEncryptedString(str)) return str;
136+
if (!isAnyEncryptedString(str)) return str;
137137
String bare = unDecorate(str);
138138
Map<String, String> attr = requireNonNull(stripAttributes(bare));
139139
if (isLegacyEncryptedString(str)) {

src/test/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcherTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.codehaus.plexus.components.secdispatcher.model.SettingsSecurity;
3333
import org.codehaus.plexus.components.secdispatcher.model.io.stax.SecurityConfigurationStaxWriter;
3434
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.params.ParameterizedTest;
36+
import org.junit.jupiter.params.provider.ValueSource;
3537

3638
import static org.junit.jupiter.api.Assertions.assertEquals;
3739
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -172,4 +174,23 @@ protected DefaultSecDispatcher construct() {
172174
new LegacyDispatcher()),
173175
CONFIG_PATH);
174176
}
177+
178+
/**
179+
* Test values created with Maven 3.9.9.
180+
* <p>
181+
* master password: "masterpassword"
182+
* password: "password"
183+
*/
184+
@ParameterizedTest
185+
@ValueSource(
186+
strings = {
187+
"src/test/legacy/legacy-settings-security-1.xml",
188+
"src/test/legacy/legacy-settings-security-2.xml"
189+
})
190+
void legacy(String xml) throws Exception {
191+
System.setProperty("settings.security", xml);
192+
SecDispatcher secDispatcher = construct();
193+
String cleartext = secDispatcher.decrypt("{L6L/HbmrY+cH+sNkphnq3fguYepTpM04WlIXb8nB1pk=}");
194+
assertEquals("password", cleartext);
195+
}
175196
}

0 commit comments

Comments
 (0)