Skip to content

Commit

Permalink
Do handle legacy as well (#79)
Browse files Browse the repository at this point in the history
It detects it, but decrypt did not handle them
  • Loading branch information
cstamas authored Nov 15, 2024
1 parent 54f7dd7 commit ab6022a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher

@Override
public String decrypt(String str) throws SecDispatcherException, IOException {
if (!isEncryptedString(str)) return str;
if (!isAnyEncryptedString(str)) return str;
String bare = unDecorate(str);
Map<String, String> attr = requireNonNull(stripAttributes(bare));
if (isLegacyEncryptedString(str)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.codehaus.plexus.components.secdispatcher.model.SettingsSecurity;
import org.codehaus.plexus.components.secdispatcher.model.io.stax.SecurityConfigurationStaxWriter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -172,4 +174,23 @@ protected DefaultSecDispatcher construct() {
new LegacyDispatcher()),
CONFIG_PATH);
}

/**
* Test values created with Maven 3.9.9.
* <p>
* master password: "masterpassword"
* password: "password"
*/
@ParameterizedTest
@ValueSource(
strings = {
"src/test/legacy/legacy-settings-security-1.xml",
"src/test/legacy/legacy-settings-security-2.xml"
})
void legacy(String xml) throws Exception {
System.setProperty("settings.security", xml);
SecDispatcher secDispatcher = construct();
String cleartext = secDispatcher.decrypt("{L6L/HbmrY+cH+sNkphnq3fguYepTpM04WlIXb8nB1pk=}");
assertEquals("password", cleartext);
}
}

0 comments on commit ab6022a

Please sign in to comment.