More unit tests

This commit is contained in:
Jamie Rees 2019-04-11 15:15:37 +01:00
commit 781cc31380
5 changed files with 166 additions and 55 deletions

View file

@ -1,46 +0,0 @@
using System;
using System.Security.Claims;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Ombi.Helpers
{
public class ClaimConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(System.Security.Claims.Claim));
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var claim = (System.Security.Claims.Claim)value;
JObject jo = new JObject();
jo.Add("Type", claim.Type);
jo.Add("Value", IsJson(claim.Value) ? new JRaw(claim.Value) : new JValue(claim.Value));
jo.Add("ValueType", claim.ValueType);
jo.Add("Issuer", claim.Issuer);
jo.Add("OriginalIssuer", claim.OriginalIssuer);
jo.WriteTo(writer);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jo = JObject.Load(reader);
string type = (string)jo["Type"];
JToken token = jo["Value"];
string value = token.Type == JTokenType.String ? (string)token : token.ToString(Formatting.None);
string valueType = (string)jo["ValueType"];
string issuer = (string)jo["Issuer"];
string originalIssuer = (string)jo["OriginalIssuer"];
return new Claim(type, value, valueType, issuer, originalIssuer);
}
private bool IsJson(string val)
{
return (val != null &&
(val.StartsWith("[") && val.EndsWith("]")) ||
(val.StartsWith("{") && val.EndsWith("}")));
}
}
}

View file

@ -1,9 +1,4 @@
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Text;
namespace Ombi.Helpers
namespace Ombi.Helpers
{
public class EmbyHelper
{
@ -11,6 +6,10 @@ namespace Ombi.Helpers
{
if (customerServerUrl.HasValue())
{
if(!customerServerUrl.EndsWith("/"))
{
return $"{customerServerUrl}/#!/itemdetails.html?id={mediaId}";
}
return $"{customerServerUrl}#!/itemdetails.html?id={mediaId}";
}
else

View file

@ -35,6 +35,11 @@ namespace Ombi.Helpers
}
else
{
if(val.EndsWith("/"))
{
// Remove a trailing slash, since the URIBuilder adds one
val = val.Remove(val.Length - 1, 1);
}
uri = new UriBuilder(Http, val);
}
@ -59,24 +64,34 @@ namespace Ombi.Helpers
}
var uri = new UriBuilder();
if (val.StartsWith("http://", StringComparison.Ordinal))
if (val.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase))
{
var split = val.Split('/');
uri = split.Length >= 4 ? new UriBuilder(Http, split[2], port, "/" + split[3]) : new UriBuilder(new Uri($"{val}:{port}"));
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
else if (val.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
var split = val.Split('/');
uri = split.Length >= 4
? new UriBuilder(Https, split[2], port, "/" + split[3])
: new UriBuilder(Https, split[2], port);
}
else if (ssl)
else if ((ssl || port == 443) && port != 80)
{
if (val.EndsWith("/"))
{
// Remove a trailing slash, since the URIBuilder adds one
val = val.Remove(val.Length - 1, 1);
}
uri = new UriBuilder(Https, val, port);
}
else
{
if (val.EndsWith("/"))
{
// Remove a trailing slash, since the URIBuilder adds one
val = val.Remove(val.Length - 1, 1);
}
uri = new UriBuilder(Http, val, port);
}