public void CreateJwkClaim(SignedHttpRequestUtilityTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.CreateJwkClaim", theoryData); try { var jwkClaim = SignedHttpRequestUtilities.CreateJwkClaim(theoryData.JsonWebKey); if (!string.IsNullOrEmpty(theoryData.ExpectedJwkClaim)) { IdentityComparer.AreStringsEqual(jwkClaim, theoryData.ExpectedJwkClaim, context); } var jwkJwt = JObject.Parse(jwkClaim); var privateKeyPropertyNames = new List <string>() { JsonWebKeyParameterNames.D, JsonWebKeyParameterNames.DP, JsonWebKeyParameterNames.DQ, JsonWebKeyParameterNames.Oth, JsonWebKeyParameterNames.P, JsonWebKeyParameterNames.Q, JsonWebKeyParameterNames.QI, }; foreach (var privateKeyPropertyName in privateKeyPropertyNames) { if (jwkJwt.ContainsKey(privateKeyPropertyName)) { context.AddDiff($"The resulting jwk claim contains '{privateKeyPropertyName}' field, that represents a private key."); } } if (new JsonWebKey(jwkClaim).HasPrivateKey) { context.AddDiff($"The resulting jwk claim contains a private key."); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void AppendHeaders(SignedHttpRequestUtilityTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.AppendHeaders", theoryData); try { var httpRequestData = new HttpRequestData { Headers = theoryData.HttpRequestHeaders }; httpRequestData.AppendHeaders(theoryData.HttpHeaders); IdentityComparer.AreStingEnumDictionariesEqual(httpRequestData.Headers, theoryData.ExpectedHttpRequestHeaders, context); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public async Task ToHttpRequestDataAsync(SignedHttpRequestUtilityTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.ToHttpRequestDataAsync", theoryData); try { var httpRequestData = await SignedHttpRequestUtilities.ToHttpRequestDataAsync(theoryData.HttpRequestMessage).ConfigureAwait(false); IdentityComparer.AreStringsEqual(httpRequestData.Method, theoryData.ExpectedHttpRequestData.Method, context); IdentityComparer.AreUrisEqual(httpRequestData.Uri, theoryData.ExpectedHttpRequestData.Uri, context); IdentityComparer.AreBytesEqual(httpRequestData.Body, theoryData.ExpectedHttpRequestData.Body, context); IdentityComparer.AreStingEnumDictionariesEqual(httpRequestData.Headers, theoryData.ExpectedHttpRequestData.Headers, context); theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }