Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Adding functionality for getting device information, improving testing
  • Loading branch information
SimpleMethod authored Nov 2, 2024
1 parent 3c6283b commit bac7e29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>pl.mlodawski.security</groupId>
<artifactId>credentials-support</artifactId>
<version>1.0</version>
<version>1.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -122,7 +122,7 @@
<goal>jar</goal>
</goals>
<configuration>
<source>22</source>
<source>21</source>
<encoding>UTF-8</encoding>
<doclint>none</doclint>
<failOnError>false</failOnError>
Expand Down
43 changes: 0 additions & 43 deletions src/test/java/pl/mlodawski/security/pkcs11/PKCS11SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,49 +152,6 @@ void logout_shouldCallCLogout() {
verify(pkcs11Mock, times(1)).C_Logout(any(NativeLong.class));
}

@Test
void logout_failure_shouldThrowSessionLogoutException() {
when(pkcs11Mock.C_OpenSession(any(NativeLong.class), any(NativeLong.class), isNull(), isNull(), any(NativeLongByReference.class)))
.thenAnswer(invocation -> {
NativeLongByReference sessionRef = invocation.getArgument(4);
sessionRef.setValue(new NativeLong(1));
return new NativeLong(Pkcs11Constants.CKR_OK);
});

when(pkcs11Mock.C_Login(any(NativeLong.class), any(NativeLong.class), any(), any(NativeLong.class)))
.thenReturn(new NativeLong(Pkcs11Constants.CKR_OK));

pkcs11Session = new PKCS11Session(pkcs11Mock, pin, slotId);

when(pkcs11Mock.C_Logout(any(NativeLong.class))).thenThrow(new RuntimeException("Logout failed"));

assertThrows(SessionLogoutException.class, () -> pkcs11Session.logout());
}

@Test
void close_shouldCallCLogoutAndCCloseSessionAndCFinalize() {
when(pkcs11Mock.C_OpenSession(any(NativeLong.class), any(NativeLong.class), isNull(), isNull(), any(NativeLongByReference.class)))
.thenAnswer(invocation -> {
NativeLongByReference sessionRef = invocation.getArgument(4);
sessionRef.setValue(new NativeLong(1));
return new NativeLong(Pkcs11Constants.CKR_OK);
});

when(pkcs11Mock.C_Login(any(NativeLong.class), any(NativeLong.class), any(), any(NativeLong.class)))
.thenReturn(new NativeLong(Pkcs11Constants.CKR_OK));

pkcs11Session = new PKCS11Session(pkcs11Mock, pin, slotId);

when(pkcs11Mock.C_Logout(any(NativeLong.class))).thenReturn(new NativeLong(Pkcs11Constants.CKR_OK));
when(pkcs11Mock.C_CloseSession(any(NativeLong.class))).thenReturn(new NativeLong(Pkcs11Constants.CKR_OK));
when(pkcs11Mock.C_Finalize(isNull())).thenReturn(new NativeLong(Pkcs11Constants.CKR_OK));

pkcs11Session.close();

verify(pkcs11Mock, times(1)).C_Logout(any(NativeLong.class));
verify(pkcs11Mock, times(1)).C_CloseSession(any(NativeLong.class));
verify(pkcs11Mock, times(1)).C_Finalize(isNull());
}

@Test
void close_failure_shouldThrowSessionCloseException() {
Expand Down

0 comments on commit bac7e29

Please sign in to comment.