'Ensure valid signature method is used.'

def test_signature_method_validation(self):

    body = u'oauth_signature=a&oauth_consumer_key=b&oauth_nonce=c&oauth_version=1.0&oauth_signature_method=%s&oauth_timestamp=1234567890'
    uri = u'https://example.com/'
    class HMACValidator(RequestValidator, ):
        @property
        def allowed_signature_methods(self):
            return (SIGNATURE_HMAC,)
    v = HMACValidator()
    e = BaseEndpoint(v)
    r = e._create_request(uri, u'GET', (body % u'RSA-SHA1'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'PLAINTEXT'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'shibboleth'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    class RSAValidator(RequestValidator, ):
        @property
        def allowed_signature_methods(self):
            return (SIGNATURE_RSA,)
    v = RSAValidator()
    e = BaseEndpoint(v)
    r = e._create_request(uri, u'GET', (body % u'HMAC-SHA1'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'PLAINTEXT'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'shibboleth'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    class PlainValidator(RequestValidator, ):
        @property
        def allowed_signature_methods(self):
            return (SIGNATURE_PLAINTEXT,)
    v = PlainValidator()
    e = BaseEndpoint(v)
    r = e._create_request(uri, u'GET', (body % u'HMAC-SHA1'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'RSA-SHA1'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
    r = e._create_request(uri, u'GET', (body % u'shibboleth'), URLENCODED)
    self.assertRaises(errors.InvalidSignatureMethodError, e._check_mandatory_parameters, r)
