...
Code Block |
---|
|
class DualShield:
headers = {"Content-Type": "application/json"}
app_context = "/das5/rest/"
def _init_(self, host, port, keyFile, certFile):
self.keyFile = keyFile
self.certFile = certFile
self.conn = HTTPSConnection(host, port, keyFile, certFile)
def execute(self, method, params):
data = json.dumps(params)
self.conn.request("POST", self.app_context + method, data, self.headers)
response = self.conn.getresponse()
data = response.read()
return json.loads(data.decode('utf-8'))
def close(self):
self.conn.close()
self.conn = None |
Anchor |
---|
| _Toc341972301 |
---|
| _Toc341972301 |
---|
|
Initialize DualShield Variables
...
Code Block |
---|
|
class TestDualShield(unittest.TestCase):
def setUp(self):
self.auth=DualShield(host, port, keyFile, certFile)
def tearDown(self):
self.auth.close() |
Anchor |
---|
| _Toc341972303 |
---|
| _Toc341972303 |
---|
|
Check the Connection
Call the"Hello" method in DualShieldto DualShield to check the connection
Code Block |
---|
|
def test_1_hello(self):
r=self.auth.execute("auth/hello", {})
|
...
Code Block |
---|
|
def test_2_staticpass(self):
#logon with 'static password' credential
username=raw_input('Please enter your login name:')
password=raw_input('Please enter your AD password:')
params = {
'user':{'loginName':username, 'domain.name':domainname},
'credential':{'method':'SPASS', 'password':password}
}
r=self.auth.execute("auth/verify", params) |
...
Code Block |
---|
|
def test_3_verifySafeID(self):
otp=raw_input('Please enter you SafeIDotp:')
params = {
'user':{'loginName':username, 'domain.name':domainname},
'credential':{'method':'OTP', 'otp':otp}
}
r=self.auth.execute("auth/verify", params) |
...
Code Block |
---|
|
def test_4_sendOTP(self):
username=raw_input('Please enter your login name:')
params = {
'user':{'loginName':username, 'domain.name':domainname},
'options':{'channel':'SMTP'}
}
r=self.auth.execute("auth/sendOTP", params) |
...
Code Block |
---|
|
def test_5_verifyODP(self):
username=raw_input('Please enter your login name:')
otp=raw_input('Please enter you otp:')
params = {
'user':{'loginName':username, 'domain.name':domainname},
'credential':{'method':'OTPoD', 'otp':otp}
}
r=self.auth.execute("auth/verify", params) |
...