Skip to content

Commit

Permalink
Fix/unit tests (#131)
Browse files Browse the repository at this point in the history
* fix PBKDF renaming

* fix bug, where `is` method was implemented wrong

* add testbase to output unit tests

Signed-off-by: Nicklas Körtge <[email protected]>

---------

Signed-off-by: Nicklas Körtge <[email protected]>
  • Loading branch information
n1ckl0sk0rtge authored Sep 4, 2024
1 parent 8f4e1a6 commit 8581e98
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 238 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public void asserts(
INode secretKeyNode = nodes.get(0);
assertThat(secretKeyNode.getKind()).isEqualTo(SecretKey.class);
assertThat(secretKeyNode.getChildren()).hasSize(4);
assertThat(secretKeyNode.asString()).isEqualTo("PBKDF2");
assertThat(secretKeyNode.asString()).isEqualTo("PBKDF2-SHA1");

// PasswordBasedKeyDerivationFunction under SecretKey
INode passwordBasedKeyDerivationFunctionNode =
secretKeyNode.getChildren().get(PasswordBasedKeyDerivationFunction.class);
assertThat(passwordBasedKeyDerivationFunctionNode).isNotNull();
assertThat(passwordBasedKeyDerivationFunctionNode.getChildren()).hasSize(3);
assertThat(passwordBasedKeyDerivationFunctionNode.asString()).isEqualTo("PBKDF2");
assertThat(passwordBasedKeyDerivationFunctionNode.asString()).isEqualTo("PBKDF2-SHA1");

// Mac under PasswordBasedKeyDerivationFunction under SecretKey
INode macNode = passwordBasedKeyDerivationFunctionNode.getChildren().get(Mac.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Map<Class<? extends INode>, INode> getChildren() {

@Override
public boolean is(@NotNull Class<? extends INode> type) {
return false;
return this.getKind().equals(type);
}

@NotNull @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void base() {
assertThat(pbkdfOptional).isPresent();
assertThat(pbkdfOptional.get()).isInstanceOf(PBKDF2.class);
assertThat(pbkdfOptional.get().is(PasswordBasedKeyDerivationFunction.class)).isTrue();
assertThat(pbkdfOptional.get().getName()).isEqualTo("PBKDF2");
assertThat(pbkdfOptional.get().getName()).isEqualTo("PBKDF2-SHA256");
assertThat(pbkdfOptional.get().getIterations()).isEmpty();
assertThat(pbkdfOptional.get().getSalt()).isEmpty();
assertThat(pbkdfOptional.get().hasChildren()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ public static IAlgorithmComponentBuilder create() {

@Override
public @NotNull Component build() {
AlgorithmVariant variant =
new AlgorithmVariant(algorithm, parameterSetIdentifier, mode, padding, curve);

if (parameterSetIdentifier != null) {
this.algorithmProperties.setParameterSetIdentifier(parameterSetIdentifier.asString());
}
Expand All @@ -393,7 +392,8 @@ public static IAlgorithmComponentBuilder create() {
this.component.setCryptoProperties(this.cryptoProperties);
this.component.setType(Component.Type.CRYPTOGRAPHIC_ASSET);
this.component.setBomRef(UUID.randomUUID().toString());
this.component.setName(variant.toString());
this.component.setName(
Optional.ofNullable(algorithm).map(INode::asString).orElse("Unknown"));

return this.component;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
*/
package com.ibm.output.cyclondx.builder;

import com.ibm.mapper.model.*;
import com.ibm.mapper.model.INode;
import com.ibm.mapper.model.Key;
import com.ibm.mapper.model.KeyLength;
import com.ibm.mapper.model.PrivateKey;
import com.ibm.mapper.model.PublicKey;
import com.ibm.mapper.model.SecretKey;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -163,15 +169,14 @@ public IKeyComponentBuilder size(@Nullable INode size) {

@Override
public @NotNull Component build() {
AlgorithmVariant variant = new AlgorithmVariant(keyAlgoName, keySize, null, null, null);

this.cryptoProperties.setAssetType(AssetType.RELATED_CRYPTO_MATERIAL);
this.cryptoProperties.setRelatedCryptoMaterialProperties(relatedCryptoMaterialProperties);

this.component.setCryptoProperties(this.cryptoProperties);
this.component.setType(Component.Type.CRYPTOGRAPHIC_ASSET);
this.component.setBomRef(UUID.randomUUID().toString());
this.component.setName("key:" + variant);
this.component.setName(
Optional.ofNullable(keyAlgoName).map(INode::asString).orElse("Unknown"));

return this.component;
}
Expand Down
Loading

0 comments on commit 8581e98

Please sign in to comment.