private WebSubSubscription PrepareWebSubSubscription(
     string subscriptionId       = WEBHOOK_ID,
     string subscriptionTopicUrl = WEBSUB_ROCKS_TOPIC_URL,
     WebSubSubscriptionState subscriptionState = WebSubSubscriptionState.SubscribeRequested)
 {
     return(new WebSubSubscription {
         Id = subscriptionId, TopicUrl = subscriptionTopicUrl, State = subscriptionState
     });
 }
 private WebSubRequestServices PrepareWebSubRequestServicesWithSecret(
     string subscriptionId = WEBHOOK_ID,
     WebSubSubscriptionState subscriptionState = WebSubSubscriptionState.SubscribeValidated)
 {
     return(new WebSubRequestServices(new Dictionary <string, WebSubSubscription>
     {
         { subscriptionId, new WebSubSubscription {
               Id = subscriptionId, State = subscriptionState, Secret = SECRET
           } }
     }));
 }
Esempio n. 3
0
 private WebSubDependencyResolver PrepareWebSubDependencyResolver(
     string subscriptionId,
     string subscriptionTopicUrl = WEBSUB_ROCKS_TOPIC_URL,
     WebSubSubscriptionState subscriptionState = WebSubSubscriptionState.SubscribeValidated,
     string secret = null)
 {
     return(new WebSubDependencyResolver(new Dictionary <string, WebSubSubscription>
     {
         { subscriptionId, new WebSubSubscription {
               Id = subscriptionId, State = subscriptionState, TopicUrl = subscriptionTopicUrl, Secret = secret
           } }
     }));
 }
Esempio n. 4
0
        public async Task OnReceiveAsync_ContentDistributionRequestForSubscriptionStateDifferentThanSubscribeValidated_ReturnsNotFoundResponse(WebSubSubscriptionState webSubSubscriptionState)
        {
            HttpRequestContext    context = PrepareWebSubRequestContext(PrepareWebSubDependencyResolver(WEBHOOK_ID, subscriptionState: webSubSubscriptionState));
            HttpRequestMessage    request = PrepareContentDistributionRequestMessage(WEBHOOK_ID, context);
            WebSubWebHookReceiver webSubWebHookReceiver = new WebSubWebHookReceiver();

            HttpResponseMessage receiveAsyncResult = await webSubWebHookReceiver.ReceiveAsync(WEBHOOK_ID, context, request);

            Assert.Equal(HttpStatusCode.NotFound, receiveAsyncResult.StatusCode);
        }
Esempio n. 5
0
        public async Task OnReceiveAsync_SubscribeIntentVerificationRequestForNotMatchingTopic_ReturnsNotFoundResponse(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            HttpRequestContext    context = PrepareWebSubRequestContext(PrepareWebSubDependencyResolver(WEBHOOK_ID, subscriptionState: webSubSubscriptionState));
            HttpRequestMessage    request = PrepareIntentVerificatioRequestMessage(WEBHOOK_ID, context, mode: mode, topic: OTHER_WEBSUB_ROCKS_TOPIC_URL);
            WebSubWebHookReceiver webSubWebHookReceiver = new WebSubWebHookReceiver();

            HttpResponseMessage receiveAsyncResult = await webSubWebHookReceiver.ReceiveAsync(WEBHOOK_ID, context, request);

            Assert.Equal(HttpStatusCode.NotFound, receiveAsyncResult.StatusCode);
        }
Esempio n. 6
0
        public async Task OnReceiveAsync_UnsubscribeIntentVerificationRequestForSubscriptionStateDifferentThanUnsubscribeRequested_ReturnsNotFoundResponse(WebSubSubscriptionState webSubSubscriptionState)
        {
            HttpRequestContext    context = PrepareWebSubRequestContext(PrepareWebSubDependencyResolver(WEBHOOK_ID, subscriptionState: webSubSubscriptionState));
            HttpRequestMessage    request = PrepareIntentVerificatioRequestMessage(WEBHOOK_ID, context, mode: INTENT_VERIFICATION_MODE_UNSUBSCRIBE);
            WebSubWebHookReceiver webSubWebHookReceiver = new WebSubWebHookReceiver();

            HttpResponseMessage receiveAsyncResult = await webSubWebHookReceiver.ReceiveAsync(WEBHOOK_ID, context, request);

            Assert.Equal(HttpStatusCode.NotFound, receiveAsyncResult.StatusCode);
        }
Esempio n. 7
0
        public async Task OnReceiveAsync_SubscribeUnsubscribeVerificationRequestWithoutChallengeParameter_ReturnsBadRequestResponse(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            HttpRequestContext    context = PrepareWebSubRequestContext(PrepareWebSubDependencyResolver(WEBHOOK_ID, subscriptionState: webSubSubscriptionState));
            HttpRequestMessage    request = PrepareIntentVerificatioRequestMessage(WEBHOOK_ID, context, mode: mode, challenge: null);
            WebSubWebHookReceiver webSubWebHookReceiver = new WebSubWebHookReceiver();

            HttpResponseMessage receiveAsyncResult = await webSubWebHookReceiver.ReceiveAsync(WEBHOOK_ID, context, request);

            Assert.Equal(HttpStatusCode.BadRequest, receiveAsyncResult.StatusCode);
        }
Esempio n. 8
0
        public async Task OnReceiveAsync_SubscribeUnsubscribeIntentVerificationRequest_ResponseContainsChallenge(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            HttpRequestContext    context = PrepareWebSubRequestContext(PrepareWebSubDependencyResolver(WEBHOOK_ID, subscriptionState: webSubSubscriptionState));
            HttpRequestMessage    request = PrepareIntentVerificatioRequestMessage(WEBHOOK_ID, context, mode: mode);
            WebSubWebHookReceiver webSubWebHookReceiver = new WebSubWebHookReceiver();

            HttpResponseMessage receiveAsyncResult = await webSubWebHookReceiver.ReceiveAsync(WEBHOOK_ID, context, request);

            Assert.Equal(WEBSUB_ROCKS_CHALLENGE, await receiveAsyncResult.Content.ReadAsStringAsync());
        }
        public async Task OnResourceExecutionAsync_ContentDistributionRequestForSubscriptionStateDifferentThanSubscribeValidated_SetsNotFoundResult(WebSubSubscriptionState webSubSubscriptionState)
        {
            ResourceExecutingContext  resourceExecutingContext  = PrepareContentDistributionExecutingContext(requestServices: PrepareWebSubRequestServices(subscriptionState: webSubSubscriptionState));
            ResourceExecutionDelegate resourceExecutionDelegate = () => Task.FromResult <ResourceExecutedContext>(null);

            WebSubWebHookSecurityFilter webSubWebHookSecurityFilter = PrepareWebSubWebHookSecurityFilter();

            await webSubWebHookSecurityFilter.OnResourceExecutionAsync(resourceExecutingContext, resourceExecutionDelegate);

            Assert.IsType <NotFoundResult>(resourceExecutingContext.Result);
        }
        public async Task OnResourceExecutionAsync_SubscribeIntentVerificationRequestForNotMatchingTopic_SetsNotFoundResult(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            ResourceExecutingContext  resourceExecutingContext  = PrepareIntentVerificatioResourceExecutingContext(mode: mode, topic: OTHER_WEBSUB_ROCKS_TOPIC_URL, subscription: PrepareWebSubSubscription(subscriptionState: webSubSubscriptionState));
            ResourceExecutionDelegate resourceExecutionDelegate = () => Task.FromResult <ResourceExecutedContext>(null);

            WebSubWebHookIntentVerificationFilter webSubWebHookIntentVerificationFilter = PrepareWebSubWebHookIntentVerificationFilter();

            await webSubWebHookIntentVerificationFilter.OnResourceExecutionAsync(resourceExecutingContext, resourceExecutionDelegate);

            Assert.IsType <NotFoundResult>(resourceExecutingContext.Result);
        }
        public async Task OnResourceExecutionAsync_UnsubscribeIntentVerificationRequestForSubscriptionStateDifferentThanUnsubscribeRequested_SetsNotFoundResult(WebSubSubscriptionState webSubSubscriptionState)
        {
            ResourceExecutingContext  resourceExecutingContext  = PrepareIntentVerificatioResourceExecutingContext(mode: INTENT_VERIFICATION_MODE_UNSUBSCRIBE, subscription: PrepareWebSubSubscription(subscriptionState: webSubSubscriptionState));
            ResourceExecutionDelegate resourceExecutionDelegate = () => Task.FromResult <ResourceExecutedContext>(null);

            WebSubWebHookIntentVerificationFilter webSubWebHookIntentVerificationFilter = PrepareWebSubWebHookIntentVerificationFilter();

            await webSubWebHookIntentVerificationFilter.OnResourceExecutionAsync(resourceExecutingContext, resourceExecutionDelegate);

            Assert.IsType <NotFoundResult>(resourceExecutingContext.Result);
        }
        public async Task OnResourceExecutionAsync_SubscribeUnsubscribeVerificationRequestWithoutChallengeParameter_SetsBadRequestObjectResult(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            ResourceExecutingContext  resourceExecutingContext  = PrepareIntentVerificatioResourceExecutingContext(mode: mode, challenge: null, subscription: PrepareWebSubSubscription(subscriptionState: webSubSubscriptionState));
            ResourceExecutionDelegate resourceExecutionDelegate = () => Task.FromResult <ResourceExecutedContext>(null);

            WebSubWebHookIntentVerificationFilter webSubWebHookIntentVerificationFilter = PrepareWebSubWebHookIntentVerificationFilter();

            await webSubWebHookIntentVerificationFilter.OnResourceExecutionAsync(resourceExecutingContext, resourceExecutionDelegate);

            Assert.IsType <BadRequestObjectResult>(resourceExecutingContext.Result);
        }
        public async Task OnResourceExecutionAsync_SubscribeUnsubscribeIntentVerificationRequest_ContentResultContainsChallenge(string mode, WebSubSubscriptionState webSubSubscriptionState)
        {
            ResourceExecutingContext  resourceExecutingContext  = PrepareIntentVerificatioResourceExecutingContext(mode: mode, subscription: PrepareWebSubSubscription(subscriptionState: webSubSubscriptionState));
            ResourceExecutionDelegate resourceExecutionDelegate = () => Task.FromResult <ResourceExecutedContext>(null);

            WebSubWebHookIntentVerificationFilter webSubWebHookIntentVerificationFilter = PrepareWebSubWebHookIntentVerificationFilter();

            await webSubWebHookIntentVerificationFilter.OnResourceExecutionAsync(resourceExecutingContext, resourceExecutionDelegate);

            Assert.Equal(WEBSUB_ROCKS_CHALLENGE, (resourceExecutingContext.Result as ContentResult).Content);
        }