//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Messages;
using DotNetOpenAuth.OpenId.Provider;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class SigningBindingElementTests : OpenIdTestBase {
///
/// Verifies that the signatures generated match Known Good signatures.
///
[TestMethod]
public void SignaturesMatchKnownGood() {
Protocol protocol = Protocol.Default;
var settings = new ProviderSecuritySettings();
var store = new AssociationMemoryStore();
byte[] associationSecret = Convert.FromBase64String("rsSwv1zPWfjPRQU80hciu8FPDC+GONAMJQ/AvSo1a2M=");
Association association = HmacShaAssociation.Create("mock", associationSecret, TimeSpan.FromDays(1));
store.StoreAssociation(AssociationRelyingPartyType.Smart, association);
SigningBindingElement signer = new SigningBindingElement(store, settings);
IndirectSignedResponse message = new IndirectSignedResponse(protocol.Version, RPUri);
ITamperResistantOpenIdMessage signedMessage = message;
message.ProviderEndpoint = ProviderUri;
signedMessage.UtcCreationDate = DateTime.Parse("1/1/2009");
signedMessage.AssociationHandle = association.Handle;
Assert.IsTrue(signer.PrepareMessageForSending(message));
Assert.AreEqual("0wOdvNgzCZ5I5AzbU58Nq2Tg8EJZ7QoNz4gpx2r7jII=", signedMessage.Signature);
}
///
/// Verifies that all parameters in ExtraData in signed responses are signed.
///
[TestMethod]
public void SignedResponsesIncludeExtraDataInSignature() {
Protocol protocol = Protocol.Default;
SigningBindingElement sbe = new SigningBindingElement(new AssociationMemoryStore(), new ProviderSecuritySettings());
IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri);
response.ReturnTo = RPUri;
response.ProviderEndpoint = ProviderUri;
response.ExtraData["someunsigned"] = "value";
response.ExtraData["openid.somesigned"] = "value";
Assert.IsTrue(sbe.PrepareMessageForSending(response));
ITamperResistantOpenIdMessage signedResponse = (ITamperResistantOpenIdMessage)response;
// Make sure that the extra parameters are signed.
// Since the signing algorithm only allows for signing parameters that start with
// 'openid.', other parameters should not be signed.
Assert.IsNotNull(signedResponse.SignedParameterOrder);
string[] signedParameters = signedResponse.SignedParameterOrder.Split(',');
Assert.IsTrue(signedParameters.Contains("somesigned"));
Assert.IsFalse(signedParameters.Contains("someunsigned"));
}
}
}