• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-cloud-agent / 10807284826

11 Sep 2024 07:46AM UTC coverage: 48.663% (+0.1%) from 48.554%
10807284826

Pull #1332

patlo-iog
test: make test work again

Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
Pull Request #1332: feat: presentation_submission validation logic [WIP]

92 of 134 new or added lines in 5 files covered. (68.66%)

248 existing lines in 65 files now uncovered.

7478 of 15367 relevant lines covered (48.66%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.1
/mercury/agent-didcommx/src/main/scala/org/hyperledger/identus/mercury/model/Conversions.scala
1
package org.hyperledger.identus.mercury.model
2

3
import io.circe.*
4
import org.didcommx.didcomm.message.{Attachment as XAttachment, MessageBuilder}
5
import org.didcommx.didcomm.message.Attachment.Data
6
import org.didcommx.didcomm.model.*
7
import org.hyperledger.identus.mercury.model.*
8

9
import scala.jdk.CollectionConverters.*
10
import scala.language.implicitConversions
11

12
given Conversion[PackEncryptedResult, EncryptedMessage] with {
13
  def apply(msg: PackEncryptedResult): EncryptedMessage = EncryptedMessageImp(msg)
×
14
}
15

16
given Conversion[Message, org.didcommx.didcomm.message.Message] with {
17
  def apply(msg: Message): org.didcommx.didcomm.message.Message = {
1✔
18
    val attachmentsAux = msg.attachments.toSeq.flatten.map { e => e: XAttachment } // cast
1✔
19
    val aux = new MessageBuilder(
1✔
20
      msg.id,
21
      // msg.body.toMap.asJava,
22
      JsonUtilsForDidCommx.fromJsonToJavaMap(msg.body),
1✔
23
      msg.piuri
1✔
24
    )
25

26
    msg.createdTime.foreach(e => aux.createdTime(e))
×
27

28
    (msg.createdTime, msg.expiresTimePlus) match {
29
      case (Some(t), Some(delta)) => aux.expiresTime(t + delta)
×
30
      case _                      => // nothing
1✔
31
    }
32
    aux.attachments(attachmentsAux.toList.asJava)
1✔
33

34
    // .customHeader("return_route", "all")
35

36
    msg.from.foreach(did => aux.from(did.value))
1✔
37
    msg.to.foreach(did => aux.to(Seq(did.value).asJava))
×
38

39
    msg.pleaseAck.foreach { seq => // https://identity.foundation/didcomm-messaging/spec/#acks
1✔
40
      aux.pleaseAck(true) // NOTE lib limitation the field pleaseAck MUST be a Array of string
1✔
41
    }
42
    msg.ack.flatMap(_.headOption).foreach(str => aux.ack(str)) // NOTE: headOption becuase DidCommx only support one ack
×
UNCOV
43
    msg.thid.foreach(str => aux.thid(str))
×
UNCOV
44
    msg.pthid.foreach(str => aux.pthid(str))
×
45
    aux.build()
1✔
46
  }
47

48
}
49

50
def json2Map(json: Json): Any = json match {
×
51
  case e if e.isArray   => e.asArray.get.toList.map(j => json2Map(j)).asJava
×
52
  case e if e.isBoolean => e.asBoolean.get
×
53
  case e if e.isNumber  => e.asNumber.flatMap(_.toBigDecimal).get
×
54
  case e if e.isObject  => e.asObject.get.toMap.view.mapValues(json2Map).toMap.asJava
×
55
  case e if e.isString  => e.asString.get
×
56
  case e if e.isNull    => null
×
57
  case _                => null // Impossible case but Json cases are private in circe ...
×
58
}
59

60
def mapValueToJson(obj: java.lang.Object): Json = {
×
61
  obj match {
62
    case null                 => Json.Null
×
63
    case b: java.lang.Boolean => Json.fromBoolean(b)
×
64
    case i: java.lang.Integer => Json.fromInt(i)
×
65
    case d: java.lang.Double =>
×
66
      Json.fromDouble(d).getOrElse(Json.fromDouble(0d).get)
×
67
    case l: java.lang.Long   => Json.fromLong(l)
×
68
    case s: java.lang.String => Json.fromString(String.valueOf(s))
×
69
    case array: com.nimbusds.jose.shaded.json.JSONArray => {
×
70
      Json.fromValues(array.iterator().asScala.map(mapValueToJson).toList)
×
71
    }
72
    case joseObject: com.nimbusds.jose.shaded.json.JSONObject =>
×
73
      Json.fromJsonObject {
×
74
        JsonObject.fromMap(
×
75
          joseObject
×
76
            .asInstanceOf[java.util.Map[String, Object]]
77
            .asScala
×
78
            .toMap
79
            .view
×
80
            .mapValues(mapValueToJson)
×
81
            .toMap
82
        )
83
      }
84
  }
85
}
86

87
given Conversion[AttachmentDescriptor, XAttachment] with {
88
  def apply(attachment: AttachmentDescriptor): XAttachment = {
×
89
    val id = attachment.id
90

91
    val data =
92
      attachment.data match {
93
        case JsonData(d) => {
×
94
          val hack: Map[String, ?] = d.toMap.view.mapValues(json2Map).toMap
×
95
          val hack2 = Map[String, Any]("jws" -> null, "hash" -> null, "json" -> hack.asJava) // OMG
×
96
          XAttachment.Data.Companion.parse(hack2.asJava)
×
97
        }
98
        case LinkData(links, hash) => new XAttachment.Data.Links(links.asJava, hash, null)
×
99
        case Base64(d)             => new XAttachment.Data.Base64(d, null, null)
×
100
        case _                     => FeatureNotImplemented
×
101
      }
102

103
    new XAttachment.Builder(id, data)
×
104
      .format(attachment.format match
×
105
        case Some(format) => format
×
106
        case None         => null
×
107
      )
108
      .build()
×
109
  }
110
}
111

112
given Conversion[XAttachment, AttachmentDescriptor] with {
113
  def apply(attachment: XAttachment): AttachmentDescriptor = {
×
114
    val data: AttachmentData = attachment.getData().toJSONObject.asScala.toMap match {
×
115
      case e if e contains ("json") =>
×
116
        val aux = e("json")
×
117
        val x = aux.asInstanceOf[java.util.Map[String, Object]].asScala.toMap.view.mapValues(mapValueToJson)
×
118
        JsonData(JsonObject.fromMap(x.toMap))
×
119
      case e if e contains ("base64") =>
×
120
        val tmp = e("base64").asInstanceOf[String] // ...
×
121
        Base64(tmp)
122
      case e if e contains ("links") =>
×
123
        val aux = e("links")
×
124
        val list = aux.asInstanceOf[java.util.AbstractList[String]]
125
        val linksSeq = list.iterator().asScala.toSeq
×
126
        LinkData(linksSeq, hash = attachment.getData().getHash())
×
127
      case e if e contains ("jws") => FeatureNotImplemented
×
128
    }
129

130
    AttachmentDescriptor(
131
      id = attachment.getId(),
×
132
      media_type = Option(attachment.getMediaType()),
×
133
      data = data,
134
      filename = Option(attachment.getFilename()),
×
135
      lastmod_time = Option(attachment.getLastModTime()),
×
136
      byte_count = Option(attachment.getByteCount()),
×
137
      description = Option(attachment.getDescription()),
×
138
      format = Option(attachment.getFormat)
×
139
    )
140
  }
141
}
142

143
given Conversion[PackSignedResult, SignedMesage] with {
144
  def apply(msg: PackSignedResult): SignedMesage = SignedMessageImp(msg)
×
145
}
146

147
given Conversion[UnpackResult, UnpackMessage] with {
148
  def apply(msg: UnpackResult): UnpackMessage = UnpackMessageImp(msg)
×
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc