public async Task CommentReport()
        {
            // create two users
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

            string           auth1             = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);
            PostUserResponse postUserResponse2 = await TestUtilities.PostGenericUser(client);

            string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);

            // create a topic from user 1
            var postTopicOperationResponse = await TestUtilities.PostGenericTopic(client, auth1);

            var topicHandle = postTopicOperationResponse.TopicHandle;

            // create a comment from user 1
            var postCommentOperationResponse = await TestUtilities.PostGenericComment(client, auth1, topicHandle);

            var commentHandle = postCommentOperationResponse.CommentHandle;

            // issue a report from user 2
            PostReportRequest postReportRequest1 = new PostReportRequest(Reason.ChildEndangermentExploitation);
            HttpOperationResponse <object> postCommentReportOperationResponse1 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postReportRequest1, authorization : auth2);

            // issue another report from user 2
            PostReportRequest postReportRequest2 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postCommentReportOperationResponse2 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postReportRequest2, authorization : auth2);

            // delete comment
            var deleteCommentOperationResponse = await TestUtilities.DeleteComment(client, commentHandle, auth1);

            // delete topic
            var deleteTopicOperationResponse = await TestUtilities.DeleteTopic(client, topicHandle, auth1);

            // issue another report from user 2 that should fail
            PostReportRequest postReportRequest3 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postCommentReportOperationResponse3 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postReportRequest3, authorization : auth2);

            // delete users
            var deleteUserOperationResponse1 = await TestUtilities.DeleteUser(client, auth1);

            var deleteUserOperationResponse2 = await TestUtilities.DeleteUser(client, auth2);

            // check failure conditions
            Assert.IsTrue(postCommentReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postCommentReportOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsFalse(postCommentReportOperationResponse3.Response.IsSuccessStatusCode);
            Assert.AreEqual(postCommentReportOperationResponse3.Response.StatusCode, System.Net.HttpStatusCode.NotFound);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
        }
        public async Task UserReport()
        {
            // create two users
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

            string           auth1             = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);
            PostUserResponse postUserResponse2 = await TestUtilities.PostGenericUser(client);

            string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);

            // issue a report from user 2 on user 1
            PostReportRequest postReportRequest1 = new PostReportRequest(Reason.ThreatsCyberbullyingHarassment);
            HttpOperationResponse <object> postUserReportOperationResponse1 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest1, authorization : auth2);

            // issue another report from user 2
            PostReportRequest postReportRequest2 = new PostReportRequest(Reason.ContentInfringement);
            HttpOperationResponse <object> postUserReportOperationResponse2 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest2, authorization : auth2);

            // issue another report from user 1 that should fail
            PostReportRequest postReportRequest3 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postUserReportOperationResponse3 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest3, authorization : auth1);

            // delete user 1
            var deleteUserOperationResponse1 = await TestUtilities.DeleteUser(client, auth1);

            // issue another report from user 2 that should fail
            PostReportRequest postReportRequest4 = new PostReportRequest(Reason.OffensiveContent);
            HttpOperationResponse <object> postUserReportOperationResponse4 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest4, authorization : auth2);

            // delete user 2
            var deleteUserOperationResponse2 = await TestUtilities.DeleteUser(client, auth2);

            // check failure conditions
            Assert.IsTrue(postUserReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postUserReportOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsFalse(postUserReportOperationResponse3.Response.IsSuccessStatusCode);
            Assert.AreEqual(postUserReportOperationResponse3.Response.StatusCode, System.Net.HttpStatusCode.Unauthorized);
            Assert.IsFalse(postUserReportOperationResponse4.Response.IsSuccessStatusCode);
            Assert.AreEqual(postUserReportOperationResponse4.Response.StatusCode, System.Net.HttpStatusCode.NotFound);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
        }
        public async Task <IHttpActionResult> PostReport(string topicHandle, [FromBody] PostReportRequest postReportRequest)
        {
            string className  = "TopicReportsController";
            string methodName = "PostReport";
            string logEntry   = $"TopicHandle = {topicHandle}, Reason = {postReportRequest?.Reason}";

            this.LogControllerStart(this.log, className, methodName, logEntry);

            // check if the content exists
            var topicEntity = await this.topicsManager.ReadTopic(topicHandle);

            if (topicEntity == null)
            {
                return(this.NotFound(ResponseStrings.TopicNotFound));
            }

            // Call the ReportControllerBase's method for posting the report. This method of the base class takes care of tracing also.
            return(await this.UpdateContentReport(className, methodName, ContentType.Topic, topicHandle, topicEntity.UserHandle, topicEntity.AppHandle, postReportRequest.Reason));
        }
        public async Task <IHttpActionResult> PostReport(string userHandle, [FromBody] PostReportRequest postReportRequest)
        {
            string className  = "UserReportsController";
            string methodName = "PostReport";
            string logEntry   = $"UserHandle = {userHandle}, Reason = {postReportRequest?.Reason}";

            this.LogControllerStart(this.log, className, methodName, logEntry);

            // check if the user exists
            var reportedUserEntity = await this.usersManager.ReadUserProfile(userHandle, this.AppHandle);

            if (reportedUserEntity == null)
            {
                return(this.NotFound(ResponseStrings.UserNotFound));
            }

            // Call the ReportControllerBase's method for posting the report. This method of the base class takes care of tracing also.
            return(await this.UpdateUserReport(className, methodName, userHandle, postReportRequest.Reason));
        }
 public IActionResult Report([FromBody] PostReportRequest request)
 {
     try
     {
         var userId = _authenticationService.GetAuthenticatedUserId(User);
         _postService.Report(request.PostId, userId);
         return(new ObjectResult(new
         {
             StatusCode = ResponseConstants.Success,
         }));
     }
     catch (PostAlreadyReportedException)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.PostAlreadyReported
         }));
     }
     catch (Exception)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.Unknown
         }));
     }
 }
Пример #6
0
        /// <summary>
        /// Report a topic as spam, offensive, etc.
        /// </summary>
        /// <param name='topicHandle'>
        /// Topic handle being reported on
        /// </param>
        /// <param name='postReportRequest'>
        /// Post report request
        /// </param>
        /// <param name='authorization'>
        /// Format is: "Scheme CredentialsList". Possible values are:
        ///
        /// - Anon AK=AppKey
        ///
        /// - SocialPlus TK=SessionToken
        ///
        /// - Facebook AK=AppKey|TK=AccessToken
        ///
        /// - Google AK=AppKey|TK=AccessToken
        ///
        /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
        ///
        /// - Microsoft AK=AppKey|TK=AccessToken
        ///
        /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <object> > PostReportWithHttpMessagesAsync(string topicHandle, PostReportRequest postReportRequest, string authorization, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (topicHandle == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "topicHandle");
            }
            if (postReportRequest == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "postReportRequest");
            }
            if (postReportRequest != null)
            {
                postReportRequest.Validate();
            }
            if (authorization == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "authorization");
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("topicHandle", topicHandle);
                tracingParameters.Add("postReportRequest", postReportRequest);
                tracingParameters.Add("authorization", authorization);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "PostReport", tracingParameters);
            }
            // Construct URL
            var _baseUrl = this.Client.BaseUri.AbsoluteUri;
            var _url     = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v0.7/topics/{topicHandle}/reports").ToString();

            _url = _url.Replace("{topicHandle}", Uri.EscapeDataString(topicHandle));
            // Create HTTP transport objects
            HttpRequestMessage  _httpRequest  = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("POST");
            _httpRequest.RequestUri = new Uri(_url);
            // Set Headers
            if (authorization != null)
            {
                if (_httpRequest.Headers.Contains("Authorization"))
                {
                    _httpRequest.Headers.Remove("Authorization");
                }
                _httpRequest.Headers.TryAddWithoutValidation("Authorization", authorization);
            }
            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (postReportRequest != null)
            {
                _requestContent      = SafeJsonConvert.SerializeObject(postReportRequest, this.Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 204 && (int)_statusCode != 400 && (int)_statusCode != 401 && (int)_statusCode != 404 && (int)_statusCode != 500)
            {
                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <object>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            // Deserialize Response
            if ((int)_statusCode == 204)
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    _result.Body = SafeJsonConvert.DeserializeObject <object>(_responseContent, this.Client.DeserializationSettings);
                }
                catch (JsonException ex)
                {
                    _httpRequest.Dispose();
                    if (_httpResponse != null)
                    {
                        _httpResponse.Dispose();
                    }
                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
                }
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
        public async Task ManualReportTesting()
        {
            // WARNING: do not run this test unless you are doing a test where you can tolerate 1-3 days of latency
            // and can manually verify the result by inspecting Azure Tables
            Assert.IsTrue(false);

            // create two users with benign profiles
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

            string           auth1             = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);
            PostUserResponse postUserResponse2 = await TestUtilities.PostGenericUser(client);

            string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);

            // issue a Threats / Cyberbullying / Harassment report from user 2 on user 1
            PostReportRequest postReportRequest1 = new PostReportRequest(Reason.ThreatsCyberbullyingHarassment);
            HttpOperationResponse <object> postUserReportOperationResponse1 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest1, authorization : auth2);

            // issue a Content Infringment report from user 2
            PostReportRequest postReportRequest2 = new PostReportRequest(Reason.ContentInfringement);
            HttpOperationResponse <object> postUserReportOperationResponse2 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest2, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postUserReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postUserReportOperationResponse2.Response.IsSuccessStatusCode);

            // create a threatening topic from user 1
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: "I am going to beat you up.", title: "You're in big trouble.", blobType: BlobType.Custom, blobHandle: null, categories: null, language: null, deepLink: null, friendlyName: null, group: null);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth1);

            string topicHandle = null;

            if (postTopicOperationResponse != null && postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }

            // issue a Threats / Cyberbullying / Harassment report from user 2
            PostReportRequest postTopicReportRequest1 = new PostReportRequest(Reason.ThreatsCyberbullyingHarassment);
            HttpOperationResponse <object> postTopicReportOperationResponse1 = await client.TopicReports.PostReportWithHttpMessagesAsync(topicHandle : topicHandle, postReportRequest : postTopicReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postTopicReportOperationResponse1.Response.IsSuccessStatusCode);

            // create a benign comment from user 1
            var postCommentOperationResponse = await TestUtilities.PostGenericComment(client, auth1, topicHandle);

            var commentHandle = postCommentOperationResponse.CommentHandle;

            // issue a Child Endangerment / Exploitation report from user 2
            PostReportRequest postCommentReportRequest1 = new PostReportRequest(Reason.ChildEndangermentExploitation);
            HttpOperationResponse <object> postCommentReportOperationResponse1 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postCommentReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postCommentReportOperationResponse1.Response.IsSuccessStatusCode);

            // create a profanity laden reply from user 1
            PostReplyRequest postReplyRequest = new PostReplyRequest(text: "f**k. shit.");
            HttpOperationResponse <PostReplyResponse> postReplyOperationResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest, authorization : auth1);

            string replyHandle = null;

            if (postReplyOperationResponse != null && postReplyOperationResponse.Response.IsSuccessStatusCode)
            {
                replyHandle = postReplyOperationResponse.Body.ReplyHandle;
            }

            // issue an Offensive Content report from user 2
            PostReportRequest postReplyReportRequest1 = new PostReportRequest(Reason.OffensiveContent);
            HttpOperationResponse <object> postReplyReportOperationResponse1 = await client.ReplyReports.PostReportWithHttpMessagesAsync(replyHandle : replyHandle, postReportRequest : postReplyReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postReplyOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postReplyReportOperationResponse1.Response.IsSuccessStatusCode);

            // do NOT clean up the users after the test ends
        }
Пример #8
0
 /// <summary>
 /// Report a user as spam, offensive, etc.
 /// </summary>
 /// This call allows a user to complain about another user's profile content
 /// (photo, bio, name) as containing spam, offensive material, etc.
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='userHandle'>
 /// User handle being reported on
 /// </param>
 /// <param name='postReportRequest'>
 /// Post report request
 /// </param>
 /// <param name='authorization'>
 /// Format is: "Scheme CredentialsList". Possible values are:
 ///
 /// - Anon AK=AppKey
 ///
 /// - SocialPlus TK=SessionToken
 ///
 /// - Facebook AK=AppKey|TK=AccessToken
 ///
 /// - Google AK=AppKey|TK=AccessToken
 ///
 /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
 ///
 /// - Microsoft AK=AppKey|TK=AccessToken
 ///
 /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> PostReportAsync(this IUserReports operations, string userHandle, PostReportRequest postReportRequest, string authorization, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostReportWithHttpMessagesAsync(userHandle, postReportRequest, authorization, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #9
0
 /// <summary>
 /// Report a user as spam, offensive, etc.
 /// </summary>
 /// This call allows a user to complain about another user's profile content
 /// (photo, bio, name) as containing spam, offensive material, etc.
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='userHandle'>
 /// User handle being reported on
 /// </param>
 /// <param name='postReportRequest'>
 /// Post report request
 /// </param>
 /// <param name='authorization'>
 /// Format is: "Scheme CredentialsList". Possible values are:
 ///
 /// - Anon AK=AppKey
 ///
 /// - SocialPlus TK=SessionToken
 ///
 /// - Facebook AK=AppKey|TK=AccessToken
 ///
 /// - Google AK=AppKey|TK=AccessToken
 ///
 /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
 ///
 /// - Microsoft AK=AppKey|TK=AccessToken
 ///
 /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
 /// </param>
 public static object PostReport(this IUserReports operations, string userHandle, PostReportRequest postReportRequest, string authorization)
 {
     return(Task.Factory.StartNew(s => ((IUserReports)s).PostReportAsync(userHandle, postReportRequest, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }