Skip to content

Commit fcd340d

Browse files
authored
Merge pull request #14 from contentstack/bug/security
Bug/security
2 parents 7de0318 + 223e6f1 commit fcd340d

20 files changed

Lines changed: 5564 additions & 21 deletions

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fileignoreconfig:
2+
- filename: Contentstack.Core/ContentstackClient.cs
3+
checksum: 2dd2ef59ca68dcc7c26d1136d6504272ac04b1840d242a57f9fabd603555225b

CHANGELOG.md

100755100644
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Version: 2.7.0
2+
#### Date: Oct-14-2021
3+
4+
##### New Feature:
5+
- Live preview feature support added
6+
17
### Version: 2.6.0
28
#### Date: Apr-05-2021
39

Contentstack.AspNetCore/Contentstack.AspNetCore.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
<PackageId>contentstack.aspnetcore</PackageId>
77
<Authors>Contentstack</Authors>
88
<Owners>Contentstack</Owners>
9-
<ReleaseVersion>2.1.1</ReleaseVersion>
10-
<PackageVersion>2.5.0</PackageVersion>
9+
<PackageVersion>2.7.0</PackageVersion>
1110
<Description>Main release</Description>
1211
<Copyright>Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
1312
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
14-
<PackageTags>v2.5.0</PackageTags>
15-
<ReleaseVersion>2.6.2</ReleaseVersion>
13+
<PackageTags>v2.7.0</PackageTags>
14+
<ReleaseVersion>2.7.0</ReleaseVersion>
1615
<Configurations>Release;Debug</Configurations>
1716
</PropertyGroup>
1817

Contentstack.Core.Tests/Contentstack.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7-
<ReleaseVersion>2.6.2</ReleaseVersion>
7+
<ReleaseVersion>2.7.0</ReleaseVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
using System;
2+
using Xunit;
3+
using Contentstack.Core.Models;
4+
using System.Threading.Tasks;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
using Contentstack.Core.Tests.Models;
9+
using Newtonsoft.Json.Linq;
10+
11+
namespace Contentstack.Core.Tests
12+
{
13+
14+
public class EntryTest
15+
{
16+
ContentstackClient client = StackConfig.GetStack();
17+
18+
////PROD STAG
19+
String source = "source";
20+
String singelEntryFetchUID = "";
21+
string htmlSource = "";
22+
String referenceFieldUID = "reference";
23+
//EU
24+
//String source = "source";
25+
//String singelEntryFetchUID = "bltf4268538a14fc5e1";
26+
//string htmlSource = "blt7c4197d43c1156ba";
27+
//String referenceFieldUID = "reference";
28+
public async Task<string> GetUID(string title)
29+
{
30+
Query query = client.ContentType(source).Query();
31+
var result = await query.Find<SourceModel>();
32+
if (result != null)
33+
{
34+
foreach (var data in result.Items)
35+
{
36+
if (data.Title == title)
37+
{
38+
return data.Uid;
39+
}
40+
}
41+
}
42+
43+
return null;
44+
}
45+
46+
[Fact]
47+
public async Task FetchByUid() {
48+
ContentType contenttype = client.ContentType(source);
49+
string uid = await GetUID("source1");
50+
Entry sourceEntry = contenttype.Entry(uid);
51+
52+
await sourceEntry.Fetch<Entry>().ContinueWith((t) =>
53+
{
54+
Entry result = t.Result;
55+
if (result == null)
56+
{
57+
Assert.False(true, "Entry.Fetch is not match with expected result.");
58+
}
59+
else
60+
{
61+
Assert.True(result.Uid == sourceEntry.Uid);
62+
}
63+
});
64+
}
65+
66+
[Fact]
67+
public async Task FetchEntryByUIDPublishFallback()
68+
{
69+
List<string> list = new List<string>();
70+
list.Add("en-us");
71+
list.Add("ja-jp");
72+
ContentType contenttype = client.ContentType(source);
73+
string uid = await GetUID("source1");
74+
Entry sourceEntry = await contenttype.Entry(uid)
75+
.SetLocale("ja-jp")
76+
.IncludeFallback()
77+
.Fetch<Entry>();
78+
79+
Assert.Contains((string)(sourceEntry.Get("publish_details") as JObject).GetValue("locale"), list);
80+
}
81+
82+
[Fact]
83+
public async Task FetchEntryByUIDPublishWithoutFallback()
84+
{
85+
List<string> list = new List<string>();
86+
list.Add("ja-jp");
87+
ContentType contenttype = client.ContentType(source);
88+
string uid = await GetUID("source1");
89+
Entry sourceEntry = await contenttype.Entry(uid)
90+
.SetLocale("ja-jp")
91+
.Fetch<Entry>();
92+
93+
Assert.Contains((string)(sourceEntry.Get("publish_details") as JObject).GetValue("locale"), list);
94+
}
95+
96+
[Fact]
97+
public async Task IncludeReference() {
98+
ContentType contenttype = client.ContentType(source);
99+
string uid = await GetUID("source1");
100+
Entry sourceEntry = contenttype.Entry(uid);
101+
102+
sourceEntry.IncludeReference(referenceFieldUID);
103+
var result = await sourceEntry.Fetch<SourceModelIncludeRef>();
104+
if (result == null) {
105+
Assert.False(true, "Query.Exec is not match with expected result.");
106+
} else {
107+
108+
bool IsTrue = false;
109+
List<Entry> lstReference = result.Reference;
110+
111+
if (lstReference.Count > 0) {
112+
IsTrue = lstReference.All(a => a is Entry);
113+
}
114+
Assert.True(IsTrue);
115+
}
116+
}
117+
118+
[Fact]
119+
public async Task IncludeReferenceArray()
120+
{
121+
ContentType contenttype = client.ContentType(source);
122+
123+
string uid = await GetUID("source1");
124+
Entry sourceEntry = contenttype.Entry(uid);
125+
126+
sourceEntry.IncludeReference(new string[] {referenceFieldUID,"other_reference"});
127+
var result = await sourceEntry.Fetch<SourceModelIncludeRefAndOther>();
128+
if (result == null)
129+
{
130+
Assert.False(true, "Query.Exec is not match with expected result.");
131+
}
132+
else
133+
{
134+
bool IsTrue = false;
135+
List<Dictionary<string, object>> firstReference = result.Reference;
136+
List<Dictionary<string, object>> secondReference = result.Other_reference;
137+
IsTrue = firstReference.All(a => a is Dictionary<string, object>);
138+
Assert.True(IsTrue);
139+
IsTrue = secondReference.All(a => a is Dictionary<string, object>);
140+
Assert.True(IsTrue);
141+
}
142+
}
143+
144+
[Fact]
145+
public async Task Only() {
146+
ContentType contenttype = client.ContentType(source);
147+
148+
string uid = await GetUID("source1");
149+
Entry sourceEntry = contenttype.Entry(uid);
150+
151+
sourceEntry.Only(new string[] { "title", "number" });
152+
SourceModel result = await sourceEntry.Fetch<SourceModel>();
153+
if (result == null) {
154+
Assert.False(true, "Query.Exec is not match with expected result.");
155+
} else {
156+
157+
List<string> uidKeys = new List<string>() { "title", "number", "uid" };
158+
bool IsTrue = false;
159+
//IsTrue = data.Object.Keys.Count == 3 && data.Object.Keys.ToList().Contains(a=> ui);
160+
IsTrue = result.Uid != null && result.Title != null && result.Number == 4 ? true : false;
161+
Assert.True(IsTrue);
162+
}
163+
}
164+
165+
[Fact]
166+
public async Task Except() {
167+
ContentType contenttype = client.ContentType(source);
168+
169+
string uid = await GetUID("source1");
170+
Entry sourceEntry = contenttype.Entry(uid);
171+
172+
sourceEntry.Except(new string[] { "title", "number" });
173+
var result = await sourceEntry.Fetch<SourceModel>();
174+
if (result == null)
175+
{
176+
Assert.False(true, "Query.Exec is not match with expected result.");
177+
}
178+
else
179+
{
180+
181+
List<string> uidKeys = new List<string>() { "title", "number" };
182+
bool IsTrue = false;
183+
IsTrue = result.Title == null && result.Number != 4.0 ? true : false;
184+
Assert.True(IsTrue);
185+
}
186+
}
187+
188+
[Fact]
189+
public async Task GetCreateAt()
190+
{
191+
ContentType contenttype = client.ContentType(source);
192+
193+
string uid = await GetUID("source1");
194+
Entry sourceEntry = contenttype.Entry(uid);
195+
196+
var result = await sourceEntry.Fetch<SourceModel>();
197+
var Created_at = result.Created_at;
198+
if (result == null)
199+
{
200+
Assert.False(true, "Query.Exec is not match with expected result.");
201+
}
202+
else
203+
{
204+
Assert.True(Created_at != default(DateTime));
205+
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
206+
}
207+
}
208+
209+
[Fact]
210+
public async Task GetUpdateAt()
211+
{
212+
ContentType contenttype = client.ContentType(source);
213+
214+
string uid = await GetUID("source1");
215+
Entry sourceEntry = contenttype.Entry(uid);
216+
217+
var result = await sourceEntry.Fetch<SourceModel>();
218+
var updated_at = result.updated_at;
219+
if (result == null)
220+
{
221+
Assert.False(true, "Query.Exec is not match with expected result.");
222+
}
223+
else
224+
{
225+
Assert.True(updated_at != default(DateTime));
226+
}
227+
}
228+
229+
[Fact]
230+
public async Task GetCreatedBy()
231+
{
232+
ContentType contenttype = client.ContentType(source);
233+
234+
string uid = await GetUID("source1");
235+
Entry sourceEntry = contenttype.Entry(uid);
236+
237+
var result = await sourceEntry.Fetch<SourceModel>();
238+
var created_by = result.created_by;
239+
if (created_by == null && created_by.Length == 0)
240+
{
241+
Assert.False(true, "Query.Exec is not match with expected result.");
242+
}
243+
else
244+
{
245+
Assert.True(created_by.Length > 0);
246+
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
247+
}
248+
}
249+
250+
[Fact]
251+
public async Task GetUpdatedBy()
252+
{
253+
ContentType contenttype = client.ContentType(source);
254+
255+
string uid = await GetUID("source1");
256+
Entry sourceEntry = contenttype.Entry(uid);
257+
258+
var result = await sourceEntry.Fetch<SourceModel>();
259+
var Updated_by = result.Updated_by;
260+
if (Updated_by == null && Updated_by.Length == 0)
261+
{
262+
Assert.False(true, "Query.Exec is not match with expected result.");
263+
}
264+
else
265+
{
266+
Assert.True(Updated_by.Length > 0);
267+
}
268+
}
269+
270+
[Fact]
271+
public async Task GetTags()
272+
{
273+
ContentType contenttype = client.ContentType(source);
274+
275+
string uid = await GetUID("source1");
276+
Entry sourceEntry = contenttype.Entry(uid);
277+
278+
var result = await sourceEntry.Fetch<SourceModel>();
279+
var Tags = result.Tags;
280+
if (Tags == null && Tags.Length == 0)
281+
{
282+
Assert.False(true, "Query.Exec is not match with expected result.");
283+
}
284+
else
285+
{
286+
Assert.True(Tags is object[] && Tags.Length > 0);
287+
}
288+
}
289+
290+
[Fact]
291+
public async Task GetHTMLText()
292+
{
293+
ContentType contenttype = client.ContentType(source);
294+
295+
string uid = await GetUID("source");
296+
Entry sourceEntry = contenttype.Entry(uid);
297+
298+
var result = await sourceEntry.Fetch<SourceModel>();
299+
300+
301+
var HtmlText = result.GetHTMLText();
302+
if (string.IsNullOrEmpty(HtmlText) && HtmlText.Length == 0) {
303+
Assert.False(true, "Query.Exec is not match with expected result.");
304+
} else {
305+
var tagList = new List<string>();
306+
string pattern = @"(?<=</?)([^ >/]+)";
307+
var matches = Regex.Matches(HtmlText, pattern);
308+
for (int i = 0; i < matches.Count; i++)
309+
{
310+
tagList.Add(matches[i].ToString());
311+
}
312+
Assert.True(!string.IsNullOrEmpty(HtmlText) && HtmlText.Length > 0 && tagList.Count > 0);
313+
}
314+
}
315+
}
316+
}

Contentstack.Core/Configuration/Config.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class Config
1515
private string _Port;
1616
private string _Version;
1717
private string _Environment;
18+
private string _Branch;
1819
#endregion
1920

2021
#region Public Properties
@@ -53,6 +54,12 @@ public string Environment
5354
set { this._Environment = value; }
5455
}
5556

57+
public string Branch
58+
{
59+
get { return this._Branch ?? null; }
60+
set { this._Branch = value; }
61+
}
62+
5663
public string BaseUrl
5764
{
5865
get
@@ -70,6 +77,18 @@ public string BaseUrl
7077

7178
#region Internal
7279

80+
internal string getBaseUrl (LivePreviewConfig livePreviewConfig, string contentTypeUID)
81+
{
82+
if (livePreviewConfig != null && livePreviewConfig.Enable && livePreviewConfig.ContentTypeUID == contentTypeUID)
83+
{
84+
return string.Format("{0}://{1}/{2}",
85+
this.Protocol.Trim('/').Trim('\\'),
86+
livePreviewConfig.Host.Trim('/').Trim('\\'),
87+
this.Version.Trim('/').Trim('\\'));
88+
}
89+
return BaseUrl;
90+
}
91+
7392
internal string regionCode()
7493
{
7594
if (Region == ContentstackRegion.US) return "";

0 commit comments

Comments
 (0)