Merge "Sync oslo's policy module"

This commit is contained in:
Jenkins 2014-02-01 21:26:34 +00:00 committed by Gerrit Code Review
commit e2f8277e8d
2 changed files with 9 additions and 8 deletions

View File

@ -56,17 +56,18 @@ as it allows particular rules to be explicitly disabled.
import abc
import re
import urllib
import urllib2
from oslo.config import cfg
import six
import six.moves.urllib.parse as urlparse
import six.moves.urllib.request as urlrequest
from keystone.openstack.common import fileutils
from keystone.openstack.common.gettextutils import _ # noqa
from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log as logging
policy_opts = [
cfg.StrOpt('policy_file',
default='policy.json',
@ -824,8 +825,8 @@ class HttpCheck(Check):
url = ('http:' + self.match) % target
data = {'target': jsonutils.dumps(target),
'credentials': jsonutils.dumps(creds)}
post_data = urllib.urlencode(data)
f = urllib2.urlopen(url, post_data)
post_data = urlparse.urlencode(data)
f = urlrequest.urlopen(url, post_data)
return f.read() == "True"

View File

@ -17,9 +17,9 @@
import json
import tempfile
import urllib2
import six
from six.moves.urllib import request as urlrequest
from testtools import matchers
from keystone import config
@ -110,7 +110,7 @@ class PolicyTestCase(tests.TestCase):
def fakeurlopen(url, post_data):
return six.StringIO("True")
self.stubs.Set(urllib2, 'urlopen', fakeurlopen)
self.stubs.Set(urlrequest, 'urlopen', fakeurlopen)
action = "example:get_http"
target = {}
result = rules.enforce(self.credentials, action, target)
@ -120,7 +120,7 @@ class PolicyTestCase(tests.TestCase):
def fakeurlopen(url, post_data):
return six.StringIO("False")
self.stubs.Set(urllib2, 'urlopen', fakeurlopen)
self.stubs.Set(urlrequest, 'urlopen', fakeurlopen)
action = "example:get_http"
target = {}
self.assertRaises(exception.ForbiddenAction, rules.enforce,