|
| 1 | +package ch.iterate.hub.core; |
| 2 | + |
| 3 | +import ch.iterate.hub.client.api.UsersResourceApi; |
| 4 | +import ch.iterate.hub.client.model.UserDto; |
| 5 | +import ch.iterate.hub.crypto.UserKeys; |
| 6 | +import ch.iterate.hub.protocols.hub.HubSession; |
| 7 | +import ch.iterate.hub.testsetup.AbstractHubTest; |
| 8 | +import ch.iterate.hub.testsetup.docker_setup.UnattendedLocalOnly; |
| 9 | +import ch.iterate.hub.testsetup.model.HubTestConfig; |
| 10 | +import com.nimbusds.jose.JOSEException; |
| 11 | +import org.junit.jupiter.api.TestInstance; |
| 12 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 13 | +import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.Arguments; |
| 15 | +import org.junit.jupiter.params.provider.MethodSource; |
| 16 | + |
| 17 | +import java.security.InvalidKeyException; |
| 18 | +import java.util.stream.Stream; |
| 19 | + |
| 20 | +import static ch.iterate.hub.testsetup.HubTestSetupConfigs.minioSTSUnattendedLocalOnly; |
| 21 | +import static ch.iterate.hub.testsetup.HubTestUtilities.setupForUser; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 24 | + |
| 25 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 26 | +@ExtendWith({UnattendedLocalOnly.class}) |
| 27 | +public class UserKeysRecoveryTest extends AbstractHubTest { |
| 28 | + |
| 29 | + private Stream<Arguments> arguments() { |
| 30 | + return Stream.of(minioSTSUnattendedLocalOnly); |
| 31 | + } |
| 32 | + |
| 33 | + @ParameterizedTest |
| 34 | + @MethodSource("arguments") |
| 35 | + public void firstLoginAndUserKeyRecovery(final HubTestConfig hubTestConfig) throws Exception { |
| 36 | + final HubSession hubSession = setupForUser(hubTestConfig.hubTestSetupConfig, hubTestConfig.hubTestSetupConfig.USER_001()); |
| 37 | + final UsersResourceApi usersApi = new UsersResourceApi(hubSession.getClient()); |
| 38 | + final UserDto me = usersApi.apiUsersMeGet(true); |
| 39 | + |
| 40 | + final JOSEException exc = assertThrows(JOSEException.class, () -> UserKeys.recover(me.getEcdhPublicKey(), me.getEcdsaPublicKey(), me.getPrivateKey(), hubTestConfig.hubTestSetupConfig.USER_001().setupCode)); |
| 41 | + assertTrue(exc.getCause() instanceof InvalidKeyException); |
| 42 | + } |
| 43 | +} |
0 commit comments