Skip to content

Commit f5c4fe9

Browse files
UMR1352eike-hass
andauthored
Credential's context is a set even when a single context value is present (#1570)
* Credential's context is a set even when a single context value is present * fix clippy warnings * update test to check for backward compatibility --------- Co-authored-by: Eike Haß <eike-hass@web.de>
1 parent 027090a commit f5c4fe9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

bindings/wasm/src/resolver/wasm_resolver.rs

-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ impl WasmResolver {
175175
.await
176176
.map_err(WasmError::from)
177177
.map_err(JsValue::from)
178-
.map(JsValue::from)
179178
});
180179

181180
Ok(promise.unchecked_into::<PromiseIToCoreDocument>())
@@ -223,7 +222,6 @@ impl WasmResolver {
223222
.map(|documents| {
224223
documents
225224
.into_iter()
226-
.map(JsValue::from)
227225
.collect::<js_sys::Array>()
228226
.unchecked_into::<JsValue>()
229227
})

identity_credential/src/credential/credential.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<T> Credential<T> {
106106
/// Returns a new `Credential` based on the `CredentialBuilder` configuration.
107107
pub fn from_builder(builder: CredentialBuilder<T>) -> Result<Self> {
108108
let this: Self = Self {
109-
context: builder.context.into(),
109+
context: OneOrMany::Many(builder.context),
110110
id: builder.id,
111111
types: builder.types.into(),
112112
credential_subject: builder.subject.into(),
@@ -199,9 +199,13 @@ where
199199

200200
#[cfg(test)]
201201
mod tests {
202+
use identity_core::common::OneOrMany;
203+
use identity_core::common::Url;
202204
use identity_core::convert::FromJson;
203205

206+
use crate::credential::credential::BASE_CONTEXT;
204207
use crate::credential::Credential;
208+
use crate::credential::Subject;
205209

206210
const JSON1: &str = include_str!("../../tests/fixtures/credential-1.json");
207211
const JSON2: &str = include_str!("../../tests/fixtures/credential-2.json");
@@ -231,4 +235,22 @@ mod tests {
231235
let _credential: Credential = Credential::from_json(JSON11).unwrap();
232236
let _credential: Credential = Credential::from_json(JSON12).unwrap();
233237
}
238+
239+
#[test]
240+
fn credential_with_single_context_is_list_of_contexts_with_single_item() {
241+
let mut credential = Credential::builder(serde_json::Value::default())
242+
.id(Url::parse("https://example.com/credentials/123").unwrap())
243+
.issuer(Url::parse("https://example.com").unwrap())
244+
.subject(Subject::with_id(Url::parse("https://example.com/users/123").unwrap()))
245+
.build()
246+
.unwrap();
247+
248+
assert!(matches!(credential.context, OneOrMany::Many(_)));
249+
assert_eq!(credential.context.len(), 1);
250+
assert!(credential.check_structure().is_ok());
251+
252+
// Check backward compatibility with previously created credentials.
253+
credential.context = OneOrMany::One(BASE_CONTEXT.clone());
254+
assert!(credential.check_structure().is_ok());
255+
}
234256
}

0 commit comments

Comments
 (0)