Skip to content

Commit b687a83

Browse files
committed
Fixes
1 parent 1913822 commit b687a83

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@
103103
</execution>
104104
</executions>
105105
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-surefire-plugin</artifactId>
109+
<configuration>
110+
<environmentVariables>
111+
<MASTER_PASSWORD>masterPw</MASTER_PASSWORD>
112+
</environmentVariables>
113+
</configuration>
114+
</plugin>
106115
</plugins>
107116
</build>
108117
</project>

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/sources/EnvMasterPasswordSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public String handle(URI uri) throws SecDispatcherException {
3939
if (!NAME.equals(uri.getScheme())) {
4040
return null;
4141
}
42-
String value = System.getenv(uri.getSchemeSpecificPart());
42+
String value = System.getenv(uri.getPath().substring(1));
4343
if (value == null) {
44-
throw new SecDispatcherException("Environment variable '" + uri.getSchemeSpecificPart() + "' not found");
44+
throw new SecDispatcherException("Environment variable '" + uri.getPath() + "' not found");
4545
}
4646
return value;
4747
}

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/sources/SystemPropertyMasterPasswordSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public String handle(URI uri) throws SecDispatcherException {
3939
if (!NAME.equals(uri.getScheme())) {
4040
return null;
4141
}
42-
String value = System.getProperty(uri.getSchemeSpecificPart());
42+
String value = System.getProperty(uri.getPath().substring(1));
4343
if (value == null) {
44-
throw new SecDispatcherException("System property '" + uri.getSchemeSpecificPart() + "' not found");
44+
throw new SecDispatcherException("System property '" + uri.getPath() + "' not found");
4545
}
4646
return value;
4747
}

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void testDecrypt() throws Exception {
106106
DefaultSecDispatcher sd = new DefaultSecDispatcher(
107107
new DefaultPlexusCipher(),
108108
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
109-
Map.of("magic", new StaticPasswordDecryptor("magic")),
109+
Map.of(),
110110
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
111111

112112
String pass = sd.decrypt(passwordEncrypted);
@@ -119,7 +119,7 @@ void testDecrypt() throws Exception {
119119
@Test
120120
void testDecryptSystemProperty() throws Exception {
121121
System.setProperty("foobar", masterPassword);
122-
saveSec("system-property:foobar");
122+
saveSec("system-property:/foobar");
123123
// /run/user/1000/gnupg/S.gpg-agent
124124
DefaultSecDispatcher sd = new DefaultSecDispatcher(
125125
new DefaultPlexusCipher(),
@@ -130,7 +130,30 @@ void testDecryptSystemProperty() throws Exception {
130130
new EnvMasterPasswordSource(),
131131
"gpg",
132132
new GpgAgentMasterPasswordSource()),
133-
Map.of("magic", new StaticPasswordDecryptor("magic")),
133+
Map.of(),
134+
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
135+
136+
String pass = sd.decrypt(passwordEncrypted);
137+
138+
assertNotNull(pass);
139+
140+
assertEquals(password, pass);
141+
}
142+
143+
@Test
144+
void testDecryptEnv() throws Exception {
145+
saveSec("env:/MASTER_PASSWORD");
146+
// /run/user/1000/gnupg/S.gpg-agent
147+
DefaultSecDispatcher sd = new DefaultSecDispatcher(
148+
new DefaultPlexusCipher(),
149+
Map.of(
150+
"prop",
151+
new SystemPropertyMasterPasswordSource(),
152+
"env",
153+
new EnvMasterPasswordSource(),
154+
"gpg",
155+
new GpgAgentMasterPasswordSource()),
156+
Map.of(),
134157
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
135158

136159
String pass = sd.decrypt(passwordEncrypted);
@@ -153,7 +176,7 @@ void testDecryptGpg() throws Exception {
153176
new EnvMasterPasswordSource(),
154177
"gpg",
155178
new GpgAgentMasterPasswordSource()),
156-
Map.of("magic", new StaticPasswordDecryptor("magic")),
179+
Map.of(),
157180
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
158181

159182
String pass = sd.decrypt(passwordEncrypted);

0 commit comments

Comments
 (0)