2222
2323import org .codehaus .plexus .components .secdispatcher .SecDispatcher ;
2424import org .codehaus .plexus .components .secdispatcher .internal .cipher .AESGCMNoPadding ;
25+ import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .ForwardingDispatcher ;
2526import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .LegacyDispatcher ;
2627import org .codehaus .plexus .components .secdispatcher .internal .dispatchers .MasterDispatcher ;
2728import org .codehaus .plexus .components .secdispatcher .internal .sources .EnvMasterSource ;
@@ -80,6 +81,18 @@ void masterWithSystemPropertyRoundTrip() throws Exception {
8081 roundtrip ();
8182 }
8283
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+
8396 @ Test
8497 void validate () throws Exception {
8598 saveSec ("master" , Map .of ("source" , "system-property:masterPassword" , "cipher" , AESGCMNoPadding .CIPHER_ALG ));
@@ -157,7 +170,7 @@ void detection() {
157170 protected void roundtrip () throws Exception {
158171 DefaultSecDispatcher sd = construct ();
159172
160- assertEquals (2 , sd .availableDispatchers ().size ());
173+ assertEquals (3 , sd .availableDispatchers ().size ());
161174 String encrypted = sd .encrypt ("supersecret" , Map .of (SecDispatcher .DISPATCHER_NAME_ATTR , "master" , "a" , "b" ));
162175 // example:
163176 // {[name=master,cipher=AES/GCM/NoPadding,a=b]vvq66pZ7rkvzSPStGTI9q4QDnsmuDwo+LtjraRel2b0XpcGJFdXcYAHAS75HUA6GLpcVtEkmyQ==}
@@ -170,6 +183,14 @@ protected void roundtrip() throws Exception {
170183 assertEquals ("supersecret" , pass );
171184 }
172185
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+
173194 protected DefaultSecDispatcher construct () {
174195 return new DefaultSecDispatcher (
175196 Map .of (
@@ -184,7 +205,15 @@ protected DefaultSecDispatcher construct() {
184205 GpgAgentMasterSource .NAME ,
185206 new GpgAgentMasterSource ())),
186207 "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 ()))),
188217 CONFIG_PATH );
189218 }
190219
0 commit comments