22
22
23
23
import org .codehaus .plexus .components .secdispatcher .SecDispatcher ;
24
24
import org .codehaus .plexus .components .secdispatcher .internal .cipher .AESGCMNoPadding ;
25
+ import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .ForwardingDispatcher ;
25
26
import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .LegacyDispatcher ;
26
27
import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .MasterDispatcher ;
27
28
import org .codehaus .plexus .components .secdispatcher .internal .sources .EnvMasterSource ;
@@ -80,6 +81,18 @@ void masterWithSystemPropertyRoundTrip() throws Exception {
80
81
roundtrip ();
81
82
}
82
83
84
+ @ Test
85
+ void forwardingWithEnvDecrypt () throws Exception {
86
+ saveSec ("forwarding" , Map .of ("source" , "env" ));
87
+ decryptForwarding ("{[name=forwarding,version=something]env:MASTER_PASSWORD}" , "masterPw" );
88
+ }
89
+
90
+ @ Test
91
+ void forwardingWithSystemPropertyDecrypt () throws Exception {
92
+ saveSec ("forwarding" , Map .of ("source" , "system-property" ));
93
+ decryptForwarding ("{[name=forwarding,version=something]system-property:masterPassword}" , "masterPw" );
94
+ }
95
+
83
96
@ Test
84
97
void validate () throws Exception {
85
98
saveSec ("master" , Map .of ("source" , "system-property:masterPassword" , "cipher" , AESGCMNoPadding .CIPHER_ALG ));
@@ -157,7 +170,7 @@ void detection() {
157
170
protected void roundtrip () throws Exception {
158
171
DefaultSecDispatcher sd = construct ();
159
172
160
- assertEquals (2 , sd .availableDispatchers ().size ());
173
+ assertEquals (3 , sd .availableDispatchers ().size ());
161
174
String encrypted = sd .encrypt ("supersecret" , Map .of (SecDispatcher .DISPATCHER_NAME_ATTR , "master" , "a" , "b" ));
162
175
// example:
163
176
// {[name=master,cipher=AES/GCM/NoPadding,a=b]vvq66pZ7rkvzSPStGTI9q4QDnsmuDwo+LtjraRel2b0XpcGJFdXcYAHAS75HUA6GLpcVtEkmyQ==}
@@ -170,6 +183,14 @@ protected void roundtrip() throws Exception {
170
183
assertEquals ("supersecret" , pass );
171
184
}
172
185
186
+ protected void decryptForwarding (String encrypted , String decrypted ) throws Exception {
187
+ DefaultSecDispatcher sd = construct ();
188
+
189
+ assertEquals (3 , sd .availableDispatchers ().size ());
190
+ String pass = sd .decrypt (encrypted );
191
+ assertEquals (decrypted , pass );
192
+ }
193
+
173
194
protected DefaultSecDispatcher construct () {
174
195
return new DefaultSecDispatcher (
175
196
Map .of (
@@ -184,7 +205,15 @@ protected DefaultSecDispatcher construct() {
184
205
GpgAgentMasterSource .NAME ,
185
206
new GpgAgentMasterSource ())),
186
207
"legacy" ,
187
- new LegacyDispatcher ()),
208
+ new LegacyDispatcher (),
209
+ "forwarding" ,
210
+ new ForwardingDispatcher (Map .of (
211
+ EnvMasterSource .NAME ,
212
+ new EnvMasterSource (),
213
+ SystemPropertyMasterSource .NAME ,
214
+ new SystemPropertyMasterSource (),
215
+ GpgAgentMasterSource .NAME ,
216
+ new GpgAgentMasterSource ()))),
188
217
CONFIG_PATH );
189
218
}
190
219
0 commit comments