public void Parse_An_Example_Input_Into_DiscoveryInformation_Successfully() { var discoveryInformationParser = new DiscoveryInformationParser(); string[] plateauCoordinates = { "5", "5" }; string[] firstRoverPosition = { "1", "2", "N" }; string[] firstRoverActions = { "L", "M", "L", "M", "L", "M", "L", "M", "M" }; string[] secondRoverPosition = { "3", "3", "E" }; string[] secondRoverActions = { "M", "M", "R", "M", "M", "R", "M", "R", "R", "M" }; DiscoveryInformation allDiscoveryInformation = discoveryInformationParser .ParseAllDiscoveryInformation(plateauCoordinates, firstRoverPosition, firstRoverActions, secondRoverPosition, secondRoverActions); Assert.NotNull(allDiscoveryInformation); Assert.AreEqual(allDiscoveryInformation.PlateauUpperRightCoordinates, new Point(5, 5)); Assert.AreEqual(allDiscoveryInformation.FirstRoverPosition.Coordinate, new Point(1, 2)); Assert.AreEqual(allDiscoveryInformation.FirstRoverPosition.Heading, Heading.N); Assert.AreEqual(allDiscoveryInformation.FirstRoverActions, new List <RoverAction> { RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.M }); Assert.AreEqual(allDiscoveryInformation.SecondRoverPosition.Coordinate, new Point(3, 3)); Assert.AreEqual(allDiscoveryInformation.SecondRoverPosition.Heading, Heading.E); Assert.AreEqual(allDiscoveryInformation.SecondRoverActions, new List <RoverAction> { RoverAction.M, RoverAction.M, RoverAction.R, RoverAction.M, RoverAction.M, RoverAction.R, RoverAction.M, RoverAction.R, RoverAction.R, RoverAction.M }); }
public async Task <DiscoveryInformation> Execute() { var result = new DiscoveryInformation(); // Returns only the exposed scopes var scopes = await _scopeRepository.GetAllAsync(); var scopeSupportedNames = new string[0]; if (scopes != null || scopes.Any()) { scopeSupportedNames = scopes.Where(s => s.IsExposed).Select(s => s.Name).ToArray(); } var responseTypesSupported = GetSupportedResponseTypes(Constants.Supported.SupportedAuthorizationFlows); var grantTypesSupported = GetSupportedGrantTypes(); var tokenAuthMethodSupported = GetSupportedTokenEndPointAuthMethods(); result.ClaimsParameterSupported = true; result.RequestParameterSupported = true; result.RequestUriParameterSupported = true; result.RequireRequestUriRegistration = true; result.ClaimsSupported = (await _claimRepository.GetAllAsync()).Select(c => c.Code).ToArray(); result.ScopesSupported = scopeSupportedNames; result.ResponseTypesSupported = responseTypesSupported; result.ResponseModesSupported = Constants.Supported.SupportedResponseModes.ToArray(); result.GrantTypesSupported = grantTypesSupported; result.SubjectTypesSupported = Constants.Supported.SupportedSubjectTypes.ToArray(); result.TokenEndpointAuthMethodSupported = tokenAuthMethodSupported; result.IdTokenSigningAlgValuesSupported = Constants.Supported.SupportedJwsAlgs.ToArray(); return(result); }
public void Operate_An_Example_Mars_Mission() { var marsDiscoveryInformation = new DiscoveryInformation { PlateauUpperRightCoordinates = new Point(5, 5), FirstRoverPosition = new RoverPosition { Coordinate = new Point(1, 2), Heading = Heading.N }, FirstRoverActions = new [] { RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.L, RoverAction.M, RoverAction.M }, SecondRoverPosition = new RoverPosition { Coordinate = new Point(3, 3), Heading = Heading.E }, SecondRoverActions = new[] { RoverAction.M, RoverAction.M, RoverAction.R, RoverAction.M, RoverAction.M, RoverAction.R, RoverAction.M, RoverAction.R, RoverAction.R, RoverAction.M }, }; var marsDiscoveryMission = new MarsDiscoveryMission(); (Rover firstRover, Rover secondRover) = marsDiscoveryMission.Discover(marsDiscoveryInformation); Assert.AreEqual(firstRover.Position.Coordinate, new Point(1, 3)); Assert.AreEqual(firstRover.Position.Heading, Heading.N); Assert.AreEqual(secondRover.Position.Coordinate, new Point(5, 1)); Assert.AreEqual(secondRover.Position.Heading, Heading.E); }
public async Task When_Getting_Token_Via_ResolveAsync_Then_GrantedToken_Is_Returned() { // ARRANGE const string discoveryUrl = "https://localhost/.well-known/openid-configuration"; const string tokenUrl = "https://localhost/token"; const string authorizationHeaderValue = "authorization"; var tokenRequest = new TokenRequest { Scope = "scope" }; var discoveryInformation = new DiscoveryInformation { TokenEndPoint = tokenUrl }; InitializeFakeObjects(); _getDiscoveryOperationStub.Setup(g => g.ExecuteAsync(It.IsAny <Uri>())).ReturnsAsync(discoveryInformation); _tokenRequestBuilderStub.Setup(t => t.AuthorizationHeaderValue).Returns(authorizationHeaderValue); _tokenRequestBuilderStub.Setup(t => t.TokenRequest).Returns(tokenRequest); // ACT var result = await _tokenClient.ResolveAsync(discoveryUrl); // ASSERT _getDiscoveryOperationStub.Verify(g => g.ExecuteAsync(new Uri(discoveryUrl))); _postTokenOperationStub.Verify(p => p.ExecuteAsync(tokenRequest, new Uri(tokenUrl), authorizationHeaderValue)); }
public void CanGetDeviceAuthorizationEndpointFromDiscoveryDocument() { DiscoveryInformation doc = null !; "When requesting discovery document".x( async() => { var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri(WellKnownOpenidConfiguration) }; request.Headers.Accept.Clear(); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await _fixture.Client().SendAsync(request).ConfigureAwait(false); var serializedContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); doc = JsonConvert.DeserializeObject <DiscoveryInformation>(serializedContent) !; }); "Then discovery document has uri for device authorization".x( () => { Assert.Equal("https://localhost/device_authorization", doc.DeviceAuthorizationEndPoint.AbsoluteUri); }); }
/// <summary> /// Initializes a new instance of the <see cref="EndpointConnectMessage"/> class. /// </summary> /// <param name="origin">The ID of the endpoint that send the message.</param> /// <param name="discoveryInformation">The object containing the information about the discovery channel for the remote endpoint.</param> /// <param name="protocolInformation">The object containing the information about the protocol channels for the remote endpoint.</param> /// <param name="information"> /// The information describing the version of the communication protocol /// used by the sender, the desired communication API's for the sender and /// the available communication API's provided by the sender. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="origin"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="discoveryInformation"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="protocolInformation"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="information"/> is <see langword="null" />. /// </exception> public EndpointConnectMessage( EndpointId origin, DiscoveryInformation discoveryInformation, ProtocolInformation protocolInformation, ProtocolDescription information) : this(origin, new MessageId(), discoveryInformation, protocolInformation, information) { }
/// <summary> /// Initializes a new instance of the <see cref="TokenClient"/> class. /// </summary> /// <param name="credentials">The <see cref="TokenCredentials"/>.</param> /// <param name="client">The <see cref="HttpClient"/> for requests.</param> /// <param name="discoveryDocumentation">The metadata information.</param> public TokenClient(TokenCredentials credentials, Func <HttpClient> client, DiscoveryInformation discoveryDocumentation) : base(client) { _form = credentials; _client = client; _authorizationValue = credentials.AuthorizationValue; _certificate = credentials.Certificate; _discovery = discoveryDocumentation; }
public (Rover firstRover, Rover secondRover) Discover(DiscoveryInformation discoveryInformation) { var firstRover = new Rover(discoveryInformation.FirstRoverPosition); var secondRover = new Rover(discoveryInformation.SecondRoverPosition); firstRover.PerformActions(discoveryInformation.FirstRoverActions); secondRover.PerformActions(discoveryInformation.SecondRoverActions); return(firstRover, secondRover); }
public async Task <DiscoveryInformation> CreateDiscoveryInformation(string issuer, CancellationToken cancellationToken) { issuer = issuer.TrimEnd('/'); // Returns only the exposed scopes var scopes = await _scopeRepository.GetAll(cancellationToken).ConfigureAwait(false); var scopeSupportedNames = scopes != null && scopes.Any() ? scopes.Where(s => s.IsExposed).Select(s => s.Name).ToArray() : Array.Empty <string>(); var responseTypesSupported = GetSupportedResponseTypes(CoreConstants.Supported.SupportedAuthorizationFlows); var result = new DiscoveryInformation { ClaimsParameterSupported = true, RequestParameterSupported = true, RequestUriParameterSupported = true, RequireRequestUriRegistration = true, ClaimsSupported = Array.Empty <string>(), ScopesSupported = scopeSupportedNames, ResponseTypesSupported = responseTypesSupported, ResponseModesSupported = CoreConstants.Supported.SupportedResponseModes.ToArray(), GrantTypesSupported = GrantTypes.All, SubjectTypesSupported = CoreConstants.Supported.SupportedSubjectTypes.ToArray(), TokenEndpointAuthMethodSupported = CoreConstants.Supported.SupportedTokenEndPointAuthenticationMethods, IdTokenSigningAlgValuesSupported = new[] { SecurityAlgorithms.RsaSha256, SecurityAlgorithms.EcdsaSha256 }, IdTokenEncryptionEncValuesSupported = Array.Empty <string>(), ClaimsLocalesSupported = new[] { "en" }, UiLocalesSupported = new[] { "en" }, Version = _version, // default : implement the session management : http://openid.net/specs/openid-connect-session-1_0.html Issuer = new Uri(issuer), DeviceAuthorizationEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.DeviceAuthorization), AuthorizationEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.Authorization), TokenEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.Token), UserInfoEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.UserInfo), JwksUri = new Uri(issuer + "/" + CoreConstants.EndPoints.Jwks), RegistrationEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.Clients), RevocationEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.Revocation), IntrospectionEndpoint = new Uri(issuer + "/" + CoreConstants.EndPoints.Introspection), Jws = new Uri(issuer + "/" + CoreConstants.EndPoints.Jws), Jwe = new Uri(issuer + "/" + CoreConstants.EndPoints.Jwe), Clients = new Uri(issuer + "/" + CoreConstants.EndPoints.Clients), Scopes = new Uri(issuer + "/" + CoreConstants.EndPoints.Scopes), ResourceOwners = new Uri(issuer + "/" + CoreConstants.EndPoints.ResourceOwners), Manage = new Uri(issuer + "/" + CoreConstants.EndPoints.Manage), Claims = new Uri(issuer + "/" + CoreConstants.EndPoints.Claims), CheckSessionEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.CheckSession), EndSessionEndPoint = new Uri(issuer + "/" + CoreConstants.EndPoints.EndSession), }; return(result); }
public void StartMission() { _discoveryMissionHumanInterface.StartMessage(); DiscoveryInformation discoveryInformation = _discoveryMissionHumanInterface.GetDiscoveryInformation(); (Rover firstRover, Rover secondRover) = _discoveryMission.Discover(discoveryInformation); _discoveryMissionHumanInterface.DiscoverySuccessfulMessage(firstRover.Position, secondRover.Position); _discoveryMissionHumanInterface.EndMessage(); }
public void Parse_An_Example_Input_Into_DiscoveryInformation_Unsuccessfully() { var discoveryInformationParser = new DiscoveryInformationParser(); string[] plateauCoordinates = { "5 ", "5vbn" }; string[] firstRoverPosition = { "** 1 fd", " 2", "N", "bn" }; string[] firstRoverActions = { "L", "fgM", "L", "M", "L", "M ", "L", "M", "M" }; string[] secondRoverPosition = { "1", "1", "sd E " }; string[] secondRoverActions = { "M", "M", "R", "Mvbn", "M", "R", "M", "R ", "R", "M" }; DiscoveryInformation allDiscoveryInformation = discoveryInformationParser .ParseAllDiscoveryInformation(plateauCoordinates, firstRoverPosition, firstRoverActions, secondRoverPosition, secondRoverActions); Assert.Null(allDiscoveryInformation); }
/// <summary> /// Initializes a new instance of the <see cref="EndpointConnectMessage"/> class. /// </summary> /// <param name="origin">The ID of the endpoint that send the message.</param> /// <param name="id">The ID of the current message.</param> /// <param name="discoveryInformation">The object containing the information about the discovery channel for the remote endpoint.</param> /// <param name="protocolInformation">The object containing the information about the protocol channels for the remote endpoint.</param> /// <param name="information"> /// The information describing the version of the communication protocol /// used by the sender, the desired communication API's for the sender and /// the available communication API's provided by the sender. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="origin"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="id"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="discoveryInformation"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="protocolInformation"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="information"/> is <see langword="null" />. /// </exception> public EndpointConnectMessage( EndpointId origin, MessageId id, DiscoveryInformation discoveryInformation, ProtocolInformation protocolInformation, ProtocolDescription information) : base(origin, id) { { Lokad.Enforce.Argument(() => discoveryInformation); Lokad.Enforce.Argument(() => protocolInformation); Lokad.Enforce.Argument(() => information); } DiscoveryInformation = discoveryInformation; ProtocolInformation = protocolInformation; Information = information; }
public void Invoke() { EndpointInformation processedChannel = null; ProtocolDescription processedDescription = null; MessageId processedMessageId = null; var sink = new Mock <IHandleProtocolHandshakes>(); { sink.Setup(s => s.ContinueHandshakeWith( It.IsAny <EndpointInformation>(), It.IsAny <ProtocolDescription>(), It.IsAny <MessageId>())) .Callback <EndpointInformation, ProtocolDescription, MessageId>((e, t, u) => { processedChannel = e; processedDescription = t; processedMessageId = u; }); } var channelTypes = new[] { ChannelTemplate.TcpIP }; var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var action = new EndpointConnectProcessAction(sink.Object, channelTypes, systemDiagnostics); var id = new EndpointId("id"); var discovery = new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")); var protocol = new ProtocolInformation( new Version(1, 0), new Uri("http://localhost/protocol/message/invalid"), new Uri("http://localhost/protocol/data/invalid")); var description = new ProtocolDescription(new List <CommunicationSubject>()); var msg = new EndpointConnectMessage(id, discovery, protocol, description); action.Invoke(msg); Assert.AreEqual(msg.Id, processedMessageId); Assert.AreEqual(id, processedChannel.Id); Assert.AreSame(discovery, processedChannel.DiscoveryInformation); Assert.AreSame(protocol, processedChannel.ProtocolInformation); Assert.AreSame(description, processedDescription); }
public void Create() { var sender = new EndpointId("sendingEndpoint"); var discovery = new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")); var protocol = new ProtocolInformation( new Version(1, 0), new Uri("http://localhost/protocol/message/invalid"), new Uri("http://localhost/protocol/data/invalid")); var description = new ProtocolDescription(new List <CommunicationSubject>()); var msg = new EndpointConnectMessage( sender, discovery, protocol, description); Assert.IsNotNull(msg.Id); Assert.AreSame(sender, msg.Sender); Assert.AreSame(discovery, msg.DiscoveryInformation); Assert.AreSame(protocol, msg.ProtocolInformation); Assert.AreSame(description, msg.Information); }
public DiscoveryInformation GetDiscoveryInformation() { Console.WriteLine("\n Please type all the discovery information: \n"); Console.Write(" "); IEnumerable <string> plateauCoordinates = Console.ReadLine()?.Split(' '); Console.Write(" "); IEnumerable <string> firstRoverPosition = Console.ReadLine()?.Split(' '); Console.Write(" "); IEnumerable <string> firstRoverActions = Console.ReadLine()?.ToCharArray().Select(c => c.ToString()); Console.Write(" "); IEnumerable <string> secondRoverPosition = Console.ReadLine()?.Split(' '); Console.Write(" "); IEnumerable <string> secondRoverActions = Console.ReadLine()?.ToCharArray().Select(c => c.ToString()); DiscoveryInformation discoveryInformation = _discoveryInformationParser.ParseAllDiscoveryInformation( plateauCoordinates, firstRoverPosition, firstRoverActions, secondRoverPosition, secondRoverActions); if (discoveryInformation == null) { Console.WriteLine("\n Please type the discovery information correctly!"); Console.Write("\n Press any key to start mission over..."); Console.ReadKey(); Console.Clear(); StartMessage(); return(GetDiscoveryInformation()); } return(discoveryInformation); }
protected void LocatedRemoteEndpointOnChannel(EndpointId id, Uri address) { // Filter out the endpoint connections that can't be used (i.e. named pipes on remote machines // or TCP/IP connections on the local machine). if (!CanReachEndpointWithGivenConnection(id, address)) { return; } var pair = GetMostSuitableDiscoveryChannel(address); if (pair == null) { m_Diagnostics.Log( LevelToLog.Info, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, Resources.Log_Messages_DiscoveryFailedToFindMatchingDiscoveryVersion_WithUri, address)); return; } Debug.Assert(m_TranslatorMap.ContainsKey(pair.Item1), "There should be a translator for the given version."); var translator = m_TranslatorMap[pair.Item1]; var protocol = translator.FromUri(pair.Item2); if (protocol == null) { return; } var discoveryInfo = new DiscoveryInformation(address); var info = new EndpointInformation(id, discoveryInfo, protocol); RaiseOnEndpointBecomingAvailable(info); }
public DiscoveryInformation ParseAllDiscoveryInformation( IEnumerable <string> plateauCoordinates, IEnumerable <string> firstRoverPosition, IEnumerable <string> firstRoverActions, IEnumerable <string> secondRoverPosition, IEnumerable <string> secondRoverActions) { var discoveryInformation = new DiscoveryInformation(); if (!ParsePlateauCoordinates(plateauCoordinates.ToList(), discoveryInformation)) { return(null); } if (!ParseRoverPosition(firstRoverPosition.ToList(), discoveryInformation.FirstRoverPosition)) { return(null); } if (!ParseRoverPosition(secondRoverPosition.ToList(), discoveryInformation.SecondRoverPosition)) { return(null); } bool result; (result, discoveryInformation.FirstRoverActions) = ParseRoverActions(firstRoverActions); if (!result) { return(null); } (result, discoveryInformation.SecondRoverActions) = ParseRoverActions(secondRoverActions); return(result ? discoveryInformation : null); }
private bool ParsePlateauCoordinates(IReadOnlyList <string> plateauCoordinates, DiscoveryInformation discoveryInformation) { if (plateauCoordinates.Count != 2) { return(false); } if (int.TryParse(plateauCoordinates[0], out int coordinate)) { discoveryInformation.PlateauUpperRightCoordinates.X = coordinate; } else { return(false); } if (int.TryParse(plateauCoordinates[1], out coordinate)) { discoveryInformation.PlateauUpperRightCoordinates.Y = coordinate; } else { return(false); } return(true); }
private ManagementClient(Func <HttpClient> client, DiscoveryInformation discoveryInformation) : base(client) { _discoveryInformation = discoveryInformation; }