throw errors on null arguments

pull/702/head
Luke Pulverenti 10 years ago
parent 0df202e397
commit 4a04483445

@ -184,6 +184,11 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task CreateServerRegistration(string wanApiAddress, string localAddress) private async Task CreateServerRegistration(string wanApiAddress, string localAddress)
{ {
if (string.IsNullOrWhiteSpace(wanApiAddress))
{
throw new ArgumentNullException("wanApiAddress");
}
var url = "Servers"; var url = "Servers";
url = GetConnectUrl(url); url = GetConnectUrl(url);
@ -212,6 +217,16 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task UpdateServerRegistration(string wanApiAddress, string localAddress) private async Task UpdateServerRegistration(string wanApiAddress, string localAddress)
{ {
if (string.IsNullOrWhiteSpace(wanApiAddress))
{
throw new ArgumentNullException("wanApiAddress");
}
if (string.IsNullOrWhiteSpace(ConnectServerId))
{
throw new ArgumentNullException("ConnectServerId");
}
var url = "Servers"; var url = "Servers";
url = GetConnectUrl(url); url = GetConnectUrl(url);
url += "?id=" + ConnectServerId; url += "?id=" + ConnectServerId;
@ -331,10 +346,18 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task<UserLinkResult> LinkUserInternal(string userId, string connectUsername) private async Task<UserLinkResult> LinkUserInternal(string userId, string connectUsername)
{ {
if (string.IsNullOrWhiteSpace(userId))
{
throw new ArgumentNullException("userId");
}
if (string.IsNullOrWhiteSpace(connectUsername)) if (string.IsNullOrWhiteSpace(connectUsername))
{ {
throw new ArgumentNullException("connectUsername"); throw new ArgumentNullException("connectUsername");
} }
if (string.IsNullOrWhiteSpace(ConnectServerId))
{
throw new ArgumentNullException("ConnectServerId");
}
var connectUser = await GetConnectUser(new ConnectUserQuery var connectUser = await GetConnectUser(new ConnectUserQuery
{ {
@ -425,6 +448,10 @@ namespace MediaBrowser.Server.Implementations.Connect
{ {
throw new ArgumentNullException("connectUsername"); throw new ArgumentNullException("connectUsername");
} }
if (string.IsNullOrWhiteSpace(ConnectServerId))
{
throw new ArgumentNullException("ConnectServerId");
}
string connectUserId = null; string connectUserId = null;
var result = new UserLinkResult(); var result = new UserLinkResult();
@ -590,6 +617,10 @@ namespace MediaBrowser.Server.Implementations.Connect
{ {
url = url + "?name=" + WebUtility.UrlEncode(query.Email); url = url + "?name=" + WebUtility.UrlEncode(query.Email);
} }
else
{
throw new ArgumentException("Empty ConnectUserQuery supplied");
}
var options = new HttpRequestOptions var options = new HttpRequestOptions
{ {
@ -616,6 +647,11 @@ namespace MediaBrowser.Server.Implementations.Connect
private void SetServerAccessToken(HttpRequestOptions options) private void SetServerAccessToken(HttpRequestOptions options)
{ {
if (string.IsNullOrWhiteSpace(ConnectAccessKey))
{
throw new ArgumentNullException("ConnectAccessKey");
}
options.RequestHeaders.Add("X-Connect-Token", ConnectAccessKey); options.RequestHeaders.Add("X-Connect-Token", ConnectAccessKey);
} }
@ -635,6 +671,11 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task RefreshAuthorizationsInternal(bool refreshImages, CancellationToken cancellationToken) private async Task RefreshAuthorizationsInternal(bool refreshImages, CancellationToken cancellationToken)
{ {
if (string.IsNullOrWhiteSpace(ConnectServerId))
{
throw new ArgumentNullException("ConnectServerId");
}
var url = GetConnectUrl("ServerAuthorizations"); var url = GetConnectUrl("ServerAuthorizations");
url += "?serverId=" + ConnectServerId; url += "?serverId=" + ConnectServerId;
@ -906,6 +947,15 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task CancelAuthorizationByConnectUserId(string connectUserId) private async Task CancelAuthorizationByConnectUserId(string connectUserId)
{ {
if (string.IsNullOrWhiteSpace(connectUserId))
{
throw new ArgumentNullException("connectUserId");
}
if (string.IsNullOrWhiteSpace(ConnectServerId))
{
throw new ArgumentNullException("ConnectServerId");
}
var url = GetConnectUrl("ServerAuthorizations"); var url = GetConnectUrl("ServerAuthorizations");
var options = new HttpRequestOptions var options = new HttpRequestOptions
@ -946,6 +996,16 @@ namespace MediaBrowser.Server.Implementations.Connect
public async Task Authenticate(string username, string passwordMd5) public async Task Authenticate(string username, string passwordMd5)
{ {
if (string.IsNullOrWhiteSpace(username))
{
throw new ArgumentNullException("username");
}
if (string.IsNullOrWhiteSpace(passwordMd5))
{
throw new ArgumentNullException("passwordMd5");
}
var request = new HttpRequestOptions var request = new HttpRequestOptions
{ {
Url = GetConnectUrl("user/authenticate") Url = GetConnectUrl("user/authenticate")
@ -972,6 +1032,11 @@ namespace MediaBrowser.Server.Implementations.Connect
private async Task TryUploadUserPreferences(User user, CancellationToken cancellationToken) private async Task TryUploadUserPreferences(User user, CancellationToken cancellationToken)
{ {
if (user == null)
{
throw new ArgumentNullException("user");
}
if (string.IsNullOrEmpty(user.ConnectUserId)) if (string.IsNullOrEmpty(user.ConnectUserId))
{ {
return; return;

Loading…
Cancel
Save