Пример #1
0
        public void Given_IAmAnEditor_WhenICreateAModerationItem_AndISpecifyTheUserIdentityKey_ThenIGetACreatedResponseCode()
        {
            const int expected = 200;

            var uri = DnaTestURLRequest.CurrentServer + "dna/api/moderation/ModerationService.svc/V1/site/h2g2/items/?d_identityuserid=dotneteditor";

            var moderationItem = new ModerationItem
            {
                CallBackUri = "http://whocares.com",
                Uri = "http://whocares.com/image.png",
                Notes = "This is great",
                BBCUserIdentity = "238011998234330627"
            };

            var client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var serialisedModerationItem = JsonConvert.SerializeObject(moderationItem);

            var content = new StringContent(serialisedModerationItem, Encoding.UTF8, "application/json" /*Content-Type*/);

            var response = client.PostAsync(uri, content).Result;

            var actual = (int)response.StatusCode;

            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        public void CreateModerationItem(string sitename, ModerationItem modItem)
        {
            try
            {
                ISite site = GetSite(sitename);
                CallingUser viewer = GetCallingUser(site);
                if (viewer.IsUserA(UserTypes.Editor))
                {
                    ExternalLinkModeration exLinkMod = new ExternalLinkModeration(base.dnaDiagnostic, base.readerCreator, base.cacheManager, base.siteList);

                    Uri source;
                    Uri callback;
                    if (Uri.TryCreate(modItem.Uri, UriKind.Absolute, out source) && Uri.TryCreate(modItem.CallBackUri, UriKind.Absolute, out callback))
                    {
                        exLinkMod.AddToModerationQueue(new Uri(modItem.Uri), new Uri(modItem.CallBackUri), modItem.ComplaintText, modItem.Notes, site.SiteID, modItem.BBCUserIdentity);
                    }
                    else
                    {
                        throw new DnaWebProtocolException(System.Net.HttpStatusCode.BadRequest, "Bad url format", null);
                    }
                }
                else
                {
                    throw new DnaWebProtocolException(System.Net.HttpStatusCode.Unauthorized, "User must be an editor", null);
                }
            }
            catch (DnaException ex)
            {
                throw new DnaWebProtocolException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
            }
        }
Пример #3
0
        public void Given_IAmAnEditor_WhenICreateAModerationItem_ThenIGetAnEmptyResponse()
        {
            const string expected = "";

            var uri = DnaTestURLRequest.CurrentServer + "dna/api/moderation/ModerationService.svc/V1/site/h2g2/items/?d_identityuserid=dotneteditor";

            var moderationItem = new ModerationItem
            {
                CallBackUri = "http://whocares.com",
                Uri = "http://whocares.com/image.png",
                Notes = "This is great",
            };

            var client = new HttpClient();

            var serialisedModerationItem = JsonConvert.SerializeObject(moderationItem);

            var content = new StringContent(serialisedModerationItem, Encoding.UTF8, "application/json" /*Content-Type*/);

            var response = client.PostAsync(uri, content).Result;

            var actual = response.Content.ReadAsStringAsync().Result;

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void CreateModerationItemInternal(string sitename, ModerationItem modItem)
        {
            try
            {
                ISite site = GetSite(sitename);
                CallingUser viewer = GetCallingUser(site);
                if (viewer.IsUserA(UserTypes.Editor))
                {
                    ExternalLinkModeration exLinkMod = new ExternalLinkModeration(base.dnaDiagnostic, base.readerCreator, base.cacheManager, base.siteList);

                    Guid keyHash = Guid.Empty;
                    string hashString = site.SiteID + "<:>" + viewer.IdentityUserID + "<:>" + modItem.Uri + "<:>" + DateTime.Now.ToString();
                    keyHash = DnaHasher.GenerateHash(hashString);
                    exLinkMod.AddToExLinkModHashInternal(keyHash, site.SiteID);

                    Uri source;
                    Uri callback;
                    string sourceURI = modItem.Uri + (modItem.Uri.IndexOf('?') > 0 ? "&" : "?") + "encryptionKey=" + keyHash;
                    string callbackURI = modItem.CallBackUri + (modItem.CallBackUri.IndexOf('?') > 0 ? "&" : "?") + "encryptionKey=" + keyHash;

                    if (Uri.TryCreate(sourceURI, UriKind.Absolute, out source) && Uri.TryCreate(callbackURI, UriKind.Absolute, out callback))
                    {
                        exLinkMod.AddToModerationQueue(new Uri(sourceURI), new Uri(callbackURI), modItem.ComplaintText, modItem.Notes, site.SiteID);
                    }
                    else
                    {
                        throw new DnaWebProtocolException(System.Net.HttpStatusCode.BadRequest, "Bad url format", null);
                    }
                }
                else
                {
                    throw new DnaWebProtocolException(System.Net.HttpStatusCode.Unauthorized, "User must be an editor", null);
                }
            }
            catch (DnaException ex)
            {
                throw new DnaWebProtocolException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
            }
        }