44
55package cloud .katta .core ;
66
7- import ch .cyberduck .core .AlphanumericRandomStringService ;
8- import ch .cyberduck .core .AttributedList ;
9- import ch .cyberduck .core .DisabledConnectionCallback ;
10- import ch .cyberduck .core .DisabledListProgressListener ;
11- import ch .cyberduck .core .ListService ;
12- import ch .cyberduck .core .OAuthTokens ;
13- import ch .cyberduck .core .Path ;
14- import ch .cyberduck .core .Session ;
15- import ch .cyberduck .core .SimplePathPredicate ;
7+ import ch .cyberduck .core .*;
168import ch .cyberduck .core .exception .AccessDeniedException ;
179import ch .cyberduck .core .exception .BackgroundException ;
1810import ch .cyberduck .core .exception .NotfoundException ;
2719import ch .cyberduck .core .features .Vault ;
2820import ch .cyberduck .core .features .Write ;
2921import ch .cyberduck .core .io .StatusOutputStream ;
22+ import ch .cyberduck .core .proxy .DisabledProxyFinder ;
23+ import ch .cyberduck .core .s3 .S3Session ;
3024import ch .cyberduck .core .transfer .Transfer ;
3125import ch .cyberduck .core .transfer .TransferItem ;
3226import ch .cyberduck .core .transfer .TransferStatus ;
33-
34- import cloud .katta .client .api .UsersResourceApi ;
27+ import ch .cyberduck .core .worker .DeleteWorker ;
3528
3629import org .apache .commons .io .IOUtils ;
3730import org .apache .commons .lang3 .RandomUtils ;
5346import java .util .EnumSet ;
5447import java .util .List ;
5548import java .util .UUID ;
49+ import java .util .stream .Collectors ;
5650
5751import cloud .katta .client .ApiClient ;
5852import cloud .katta .client .ApiException ;
53+ import cloud .katta .client .api .ConfigResourceApi ;
5954import cloud .katta .client .api .StorageProfileResourceApi ;
55+ import cloud .katta .client .api .UsersResourceApi ;
56+ import cloud .katta .client .api .VaultResourceApi ;
57+ import cloud .katta .client .model .ConfigDto ;
58+ import cloud .katta .client .model .Protocol ;
6059import cloud .katta .client .model .S3SERVERSIDEENCRYPTION ;
6160import cloud .katta .client .model .S3STORAGECLASSES ;
6261import cloud .katta .client .model .StorageProfileDto ;
6362import cloud .katta .client .model .StorageProfileS3Dto ;
6463import cloud .katta .client .model .StorageProfileS3STSDto ;
6564import cloud .katta .crypto .UserKeys ;
65+ import cloud .katta .crypto .uvf .VaultMetadataJWEBackendDto ;
6666import cloud .katta .model .StorageProfileDtoWrapper ;
6767import cloud .katta .protocols .hub .HubSession ;
6868import cloud .katta .protocols .hub .HubVaultRegistry ;
7272import cloud .katta .workflows .CreateVaultService ;
7373import cloud .katta .workflows .DeviceKeysServiceImpl ;
7474import cloud .katta .workflows .UserKeysServiceImpl ;
75+ import cloud .katta .workflows .VaultServiceImpl ;
7576import com .fasterxml .jackson .annotation .JsonInclude ;
7677import com .fasterxml .jackson .databind .ObjectMapper ;
7778
@@ -228,6 +229,30 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
228229 log .info ("Creating vault in {}" , hubSession );
229230 final UUID vaultId = UUID .randomUUID ();
230231
232+
233+ if (storageProfileWrapper .getProtocol () == Protocol .S3 ) {
234+ // empty bucket
235+ final HostPasswordStore keychain = PasswordStoreFactory .get ();
236+
237+ final OAuthTokens tokens = keychain .findOAuthTokens (hubSession .getHost ());
238+ final Host bookmark = new VaultServiceImpl (new VaultResourceApi (hubSession .getClient ()), new StorageProfileResourceApi (hubSession .getClient ()))
239+ .getStorageBackend (
240+ ProtocolFactory .get (),
241+ new ConfigResourceApi (hubSession .getClient ()).apiConfigGet (), vaultId , new VaultMetadataJWEBackendDto ()
242+ .provider (storageProfileWrapper .getId ().toString ())
243+ .defaultPath (config .vault .bucketName )
244+ .nickname (config .vault .bucketName )
245+ .username (config .vault .username )
246+ .password (config .vault .password ), tokens );
247+ final S3Session session = new S3Session (bookmark );
248+ session .open (new DisabledProxyFinder (), new DisabledHostKeyCallback (), new DisabledLoginCallback (), new DisabledCancelCallback ());
249+ session .login (new DisabledLoginCallback (), new DisabledCancelCallback ());
250+ new DeleteWorker (new DisabledLoginCallback (),
251+ session .getFeature (ListService .class ).list (new Path ("/" + config .vault .bucketName , EnumSet .of (AbstractPath .Type .directory )), new DisabledListProgressListener ()).toStream ().filter (f -> session .getFeature (Delete .class ).isSupported (f )).collect (Collectors .toList ()),
252+ new DisabledListProgressListener ()).run (session );
253+ session .close ();
254+ }
255+
231256 final UserKeys userKeys = new UserKeysServiceImpl (hubSession ).getUserKeys (hubSession .getHost (), hubSession .getMe (),
232257 new DeviceKeysServiceImpl ().getDeviceKeys (hubSession .getHost ()));
233258 new CreateVaultService (hubSession ).createVault (userKeys , storageProfileWrapper , new CreateVaultService .CreateVaultModel (
@@ -237,7 +262,7 @@ public void test03AddVault(final HubTestConfig config) throws Exception {
237262 final AttributedList <Path > vaults = hubSession .getFeature (ListService .class ).list (Home .ROOT , new DisabledListProgressListener ());
238263 assertFalse (vaults .isEmpty ());
239264
240- final Path bucket = new Path (storageProfileWrapper .getStsEndpoint () != null ? storageProfileWrapper .getBucketPrefix () + vaultId : config .vault .bucketName ,
265+ final Path bucket = new Path (storageProfileWrapper .getProtocol () == Protocol . S3_STS ? storageProfileWrapper .getBucketPrefix () + vaultId : config .vault .bucketName ,
241266 EnumSet .of (Path .Type .volume , Path .Type .directory ));
242267 final HubVaultRegistry vaultRegistry = hubSession .getRegistry ();
243268 {
@@ -326,9 +351,11 @@ public void test04SetupCode(final HubTestConfig config) throws Exception {
326351 assertEquals (StringUtils .EMPTY , hubSession .getHost ().getCredentials ().getPassword ());
327352 final ListService feature = hubSession .getFeature (ListService .class );
328353 final AttributedList <Path > vaults = feature .list (Home .ROOT , new DisabledListProgressListener ());
329- assertEquals (2 , vaults .size ());
354+ final ConfigDto configDto = new ConfigResourceApi (hubSession .getClient ()).apiConfigGet ();
355+ final int expectedNumberOfVaults = configDto .getKeycloakTokenEndpoint ().contains ("localhost" ) ? 2 : 4 ;
356+ assertEquals (expectedNumberOfVaults , vaults .size ());
330357 assertEquals (vaults , feature .list (Home .ROOT , new DisabledListProgressListener ()));
331- for (Path vault : vaults ) {
358+ for (final Path vault : vaults ) {
332359 assertTrue (hubSession .getFeature (Find .class ).find (vault ));
333360 }
334361 new UsersResourceApi (hubSession .getClient ()).apiUsersMeGet (true );
0 commit comments