Query query;
Template origTemplate = Parser.parse( "http://host:0/path/file?query-param-name=query-param-value" );
// Test encryption. Results are left in encTemplate
AliasService as = EasyMock.createNiceMock( AliasService.class );
String secret = "sdkjfhsdkjfhsdfs";
EasyMock.expect( as.getPasswordFromAliasForCluster("test-cluster-name", "encryptQueryString")).andReturn( secret.toCharArray() ).anyTimes();
CryptoService cryptoService = new DefaultCryptoService();
((DefaultCryptoService)cryptoService).setAliasService(as);
GatewayServices gatewayServices = EasyMock.createNiceMock( GatewayServices.class );
EasyMock.expect( gatewayServices.getService( GatewayServices.CRYPTO_SERVICE ) ).andReturn( cryptoService );
UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
EasyMock.expect( encEnvironment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();
EasyMock.expect( encEnvironment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster-name" ).anyTimes();
UrlRewriteContext encContext = EasyMock.createNiceMock( UrlRewriteContext.class );
EasyMock.expect( encContext.getCurrentUrl() ).andReturn( origTemplate );
Capture<Template> encTemplate = new Capture<Template>();
encContext.setCurrentUrl( EasyMock.capture( encTemplate ) );
EasyMock.replay( gatewayServices, as, encEnvironment, encContext );
SecureQueryEncryptDescriptor descriptor = new SecureQueryEncryptDescriptor();
SecureQueryEncryptProcessor processor = new SecureQueryEncryptProcessor();
processor.initialize( encEnvironment, descriptor );
processor.process( encContext );
assertThat( encTemplate, notNullValue() );
query = encTemplate.getValue().getQuery().get( "_" );
assertThat( query.getFirstValue().getPattern().length(), greaterThan( 1 ) );
query = encTemplate.getValue().getQuery().get( "query-param-name" );
assertThat( query, nullValue() );
// Test decryption. Results are left in decTemplate.
gatewayServices = EasyMock.createNiceMock( GatewayServices.class );
EasyMock.expect( gatewayServices.getService( GatewayServices.CRYPTO_SERVICE ) ).andReturn( cryptoService );
as = EasyMock.createNiceMock( AliasService.class );
EasyMock.expect( as.getPasswordFromAliasForCluster("test-cluster-name", "encryptQueryString")).andReturn( secret.toCharArray() ).anyTimes();
UrlRewriteEnvironment decEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
EasyMock.expect( decEnvironment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();
EasyMock.expect( decEnvironment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster-name" ).anyTimes();
Params decParams = EasyMock.createNiceMock( Params.class );