Beispiel #1
0
 public OAuthException(IConsumerResponse consumerResponse, IOAuthContext requestContext, OAuthProblemReport problemReport)
     : base(problemReport.ProblemAdvice)
 {
     ConsumerResponse = consumerResponse;
     Report = problemReport;
     Context = requestContext;
 }
Beispiel #2
0
 public OAuthException(IOAuthContext context, string problem, string advice) : base(advice)
 {
     Context = context;
     Report  = new OAuthProblemReport {
         Problem = problem, ProblemAdvice = advice
     };
 }
 public OAuthException(IConsumerResponse consumerResponse, IOAuthContext requestContext, OAuthProblemReport problemReport)
     : base(problemReport.ProblemAdvice)
 {
     ConsumerResponse = consumerResponse;
     Report           = problemReport;
     Context          = requestContext;
 }
		public void FormatMissingParameterReport()
		{
			var report = new OAuthProblemReport
			             	{
			             		Problem = OAuthProblems.ParameterAbsent,
			             		ParametersAbsent = {Parameters.OAuth_Nonce}
			             	};

			Assert.Equal("oauth_problem=parameter_absent&oauth_parameters_absent=oauth_nonce", report.ToString());
		}
		public void FormatRejectedParameterReport()
		{
			var report = new OAuthProblemReport
			             	{
			             		Problem = OAuthProblems.ParameterRejected,
			             		ParametersRejected = {Parameters.OAuth_Timestamp}
			             	};

			Assert.Equal("oauth_problem=parameter_rejected&oauth_parameters_rejected=oauth_timestamp",
			             report.ToString());
		}
		public void FormatTimestampRangeReport()
		{
			var report = new OAuthProblemReport
			             	{
			             		Problem = OAuthProblems.TimestampRefused,
			             		AcceptableTimeStampsFrom = new DateTime(2008, 1, 1),
			             		AcceptableTimeStampsTo = new DateTime(2009, 1, 1)
			             	};

			Assert.Equal("oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1199098800-1230721200",
			             report.ToString());
		}
		public void FormatReportWithAdvice()
		{
			var report = new OAuthProblemReport
			             	{
			             		Problem = OAuthProblems.ConsumerKeyRefused,
			             		ProblemAdvice = "The supplied consumer key has been black-listed due to complaints."
			             	};

			Assert.Equal(
				"oauth_problem=consumer_key_refused&oauth_problem_advice=The%20supplied%20consumer%20key%20has%20been%20black-listed%20due%20to%20complaints.",
				report.ToString());
		}
    /// <summary>
    /// Will attempt to wrap the exception, returning true if the exception was wrapped, or returning false if it was not (in which case
    /// the original exception should be thrown).
    /// </summary>
    /// <param name="requestContext"></param>
    /// <param name="webEx"></param>
    /// <param name="authException"></param>
    /// <returns><c>true</c>, if the authException should be throw, <c>false</c> if the original web exception should be thrown</returns>
    public static bool TryWrapException(IOAuthContext requestContext, WebException webEx, out OAuthException authException)
    {
      try
      {
        string content = webEx.Response.ReadToEnd();

        if (content.Contains(Parameters.OAuth_Problem))
        {
          var report = new OAuthProblemReport(content);
          authException = new OAuthException(report.ProblemAdvice ?? report.Problem, webEx) {Context = requestContext, Report = report};
          return true;
        }
      }
      catch
      {
      }
      authException = new OAuthException();
      return false;
    }
        /// <summary>
        /// Will attempt to wrap the exception, returning true if the exception was wrapped, or returning false if it was not (in which case
        /// the original exception should be thrown).
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="webException"></param>
        /// <param name="wrappedException">The wrapped exception (will be set to the webException, if this method returns <c>false</c></param>
        /// <returns><c>true</c>, if the authException should be throw, <c>false</c> if the wrapped web exception should be thrown</returns>
        public static bool TryWrapException(IOAuthContext requestContext, WebException webException, out Exception wrappedException)
        {
            try
            {
                string content = webException.Response.ReadToEnd();

                if (content.Contains(Parameters.OAuth_Problem))
                {
                  var report = new OAuthProblemReport(content);
                  wrappedException = new OAuthException(report.ProblemAdvice ?? report.Problem, webException) { Context = requestContext, Report = report };
                }
                else
                {
                  wrappedException = new ParsedWebException(content, webException.Message, webException.GetBaseException(), webException.Status, webException.Response);
                }

                return true;
            }
            catch
            {
              wrappedException = webException;
              return false;
            }          
        }
Beispiel #10
0
 public OAuthException(IOAuthContext context, string problem, string advice, Exception innerException)
   : base(advice, innerException)
 {
   Context = context;
   Report = new OAuthProblemReport() {Problem = problem, ProblemAdvice = advice};
 }
		public void FormatVersionRangeReport()
		{
			var report = new OAuthProblemReport
			             	{
			             		Problem = OAuthProblems.VersionRejected,
			             		AcceptableVersionFrom = "1.0",
			             		AcceptableVersionTo = "2.0"
			             	};

			Assert.Equal("oauth_problem=version_rejected&oauth_acceptable_versions=1.0-2.0", report.ToString());
		}
		public void PopulateFromFormattedVersionRangeReport()
		{
			string formatted = "oauth_problem=version_rejected&oauth_acceptable_versions=1.0-2.0";

			var report = new OAuthProblemReport(formatted);

			Assert.Equal(OAuthProblems.VersionRejected, report.Problem);
			Assert.Equal("1.0", report.AcceptableVersionFrom);
			Assert.Equal("2.0", report.AcceptableVersionTo);
		}
		public void PopulateFromFormattedTimestampRangeReport()
		{
			string formatted = "oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1199098800-1230721200";

			var report = new OAuthProblemReport(formatted);

			Assert.Equal(OAuthProblems.TimestampRefused, report.Problem);
			Assert.Equal(new DateTime(2008, 1, 1), report.AcceptableTimeStampsFrom);
			Assert.Equal(new DateTime(2009, 1, 1), report.AcceptableTimeStampsTo);
		}
		public void PopulateFromFormattedReportWithAdvice()
		{
			string formatted =
				"oauth_problem=consumer_key_refused&oauth_problem_advice=The%20supplied%20consumer%20key%20has%20been%20black-listed%20due%20to%20complaints.";

			var report = new OAuthProblemReport(formatted);

			Assert.Equal(report.Problem, OAuthProblems.ConsumerKeyRefused);
			Assert.Equal("The supplied consumer key has been black-listed due to complaints.", report.ProblemAdvice);
		}
		public void PopulateFromFormattedRejectedParameterReport()
		{
			string formatted = "oauth_problem=parameter_rejected&oauth_parameters_rejected=oauth_timestamp";

			var report = new OAuthProblemReport(formatted);

			Assert.Equal(OAuthProblems.ParameterRejected, report.Problem);
			Assert.Contains(Parameters.OAuth_Timestamp, report.ParametersRejected);
		}
		public void PopulateFromFormattedMissingParameterReport()
		{
			string formatted = "oauth_problem=parameter_absent&oauth_parameters_absent=oauth_nonce";

			var report = new OAuthProblemReport(formatted);

			Assert.Equal(OAuthProblems.ParameterAbsent, report.Problem);
			Assert.Contains(Parameters.OAuth_Nonce, report.ParametersAbsent);
		}