def init_provider(email): org_domain = email.split('@')[1] org_id = add_organization(org_domain) try: # deletes all rules also cursor.execute("delete from consent.users where users.email = '" + email + "'") conn.commit() except psycopg2.DatabaseError as error: return {} r = provider_reg(email, '7529547992', name, org_id, csr) try: cursor.execute( "update consent.role as rr set status = 'approved' from consent.users where " + " users.id = rr.user_id and users.email = '" + email + "'") conn.commit() except psycopg2.DatabaseError as error: return {}
def init_admin(): org_id = add_organization("rbccps.org") # use [email protected] certificate as provider # do not assert, can already be approved r = provider_reg("*****@*****.**", '7529547992', name , org_id, csr) try: cursor.execute("select id from consent.users where users.email = '*****@*****.**'") oid = cursor.fetchone()[0] cursor.execute("insert into consent.role (user_id,role,status,created_at,updated_at) values (" + str(oid) + ",'admin','approved',now(),now())") conn.commit() except psycopg2.DatabaseError as error: return {}
def init_provider(): org_id = add_organization("rbccps.org") # use [email protected] certificate as provider # do not assert, can already be approved r = provider_reg("*****@*****.**", '7529547992', name, org_id, csr) try: cursor.execute( "update consent.role as rr set status = 'approved' from consent.users where " + " users.id = rr.user_id and users.email = '*****@*****.**'") cursor.execute( "delete from consent.access using consent.users where access.provider_id = users.id and email = '*****@*****.**' and access_item_type = 'catalogue'" ) cursor.execute( "delete from consent.access using consent.users where access.provider_id = users.id and email = '*****@*****.**' and access_item_type = 'delegate'" ) conn.commit() except psycopg2.DatabaseError as error: return {}
name = {"title": "mr.", "firstName": "abc", "lastName": "xyz"} csr = "-----BEGIN CERTIFICATE REQUEST-----\nMIICjDCCAXQCAQAwRzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRQwEgYDVQQK\nDAtNeU9yZywgSW5jLjEVMBMGA1UEAwwMbXlkb21haW4uY29tMIIBIjANBgkqhkiG\n9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyhF2a5PeL72zGdL47/6zVQQQtZJcO01iVbjR\nSSyswUa2jcfYfoQEVKo1JAz25G3nYfSW1Te3OWjuihvPhZeatFSUwTxcZJFxzIWm\n4/gOQIhJKCA/Wry3li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FfgT5Ecbqsc2nqChAExgocp5tkPJYcy8FB/tU/FW0rFthqecSvMrpS\ncZW9+iyzseyPrcK9ka6XSlVu9EoX82RW7SRyRL2T5VN3JemXfQIDAQABoAAwDQYJ\nKoZIhvcNAQELBQADggEBAJRFEYn6dSzEYpgYLItUm7Sp3LzquJw7QfMyUvsy45rp\n0VTdQdYp/hVR2aCLiD33ht4FxlhbZm/8XcTuYolP6AbF6FldxWmmFFS9LRAj7nTV\ndU1pZftwFPp6JsKUCYHVsuxs7swliXbEcBVtD6QktzZNrRJmUKi38DAFcbFwgLaM\nG/iRIm4DDj2hmanKp+vUWjXfj13nasaswwa7bDtIlzW96y24jsu+naabg8MVShfGCStIv\nrX3T2JkkSjpTw7YzIpgI8/Zg9VR1l0udvfh9bn7sdakjsd92jkamjmOYc3EYwJKvuJDn1TzVuIIi\n9NmVasTjhZJ0PyWithWuZplo/LXUwSoid8HVyqe5ZVI=\n-----END CERTIFICATE REQUEST-----\n" # random website website = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) + '.com' # random email email_name = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(6)) email = email_name + '@gmail.com' org_id = add_organization(website) def test_no_role(): # no role specified r = role_reg(email, '9454234223', name, [], None, csr) assert r['success'] == False assert r['status_code'] == 400 def test_success(): r = role_reg(email, '9454234223', name, ["consumer"], None, csr) print(r) assert r['success'] == True assert r['status_code'] == 200
import string def test_invalid_input(): # invalid inputs r = provider_reg('a', 'b', 'c', 'd', 'e') assert r['success'] == False assert r['status_code'] == 400 name = {"title": "mr.", "firstName": "abc", "lastName": "xyz"} website = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) + '.com' org_id = add_organization(website) csr = "-----BEGIN CERTIFICATE REQUEST-----\nMIICjDCCAXQCAQAwRzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRQwEgYDVQQK\nDAtNeU9yZywgSW5jLjEVMBMGA1UEAwwMbXlkb21haW4uY29tMIIBIjANBgkqhkiG\n9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyhF2a5PeL72zGdL47/6zVQQQtZJcO01iVbjR\nSSyswUa2jcfYfoQEVKo1JAz25G3nYfSW1Te3OWjuihvPhZeatFSUwTxcZJFxzIWm\n4/gOQIhJKCA/Wry3liW2sjIGLuHxeH2BoQCIEZyYcqVpRWEJ9RusRFcwPgvROigh\nhMXhgE86uaIRs0yPqzhc7sl53T4qx6qvQJ6uTXBWBvUELgSSgeyaT0gwU1mGmPck\n7Svo6tsWfBFfgT5Ecbqsc2nqChAExgocp5tkPJYcy8FB/tU/FW0rFthqecSvMrpS\ncZW9+iyzseyPrcK9ka6XSlVu9EoX82RW7SRyRL2T5VN3JemXfQIDAQABoAAwDQYJ\nKoZIhvcNAQELBQADggEBAJRFEYn6dSzEYpgYLItUm7Sp3LzquJw7QfMyUvsy45rp\n0VTdQdYp/hVR2aCLiD33ht4FxlhbZm/8XcTuYolP6AbF6FldxWmmFFS9LRAj7nTV\ndU1pZftwFPp6JsKUCYHVsuxs7swliXbEcBVtD6QktzZNrRJmUKi38DAFcbFwgLaM\nG/iRIm4DDj2hmanKp+vUWjXfj13naa7bDtIlzW96y24jsu+naabg8MVShfGCStIv\nrX3T2JkkSjpTw7YzIpgI8/Zg9VR1l0udvfh9bn7mjmOYc3EYwJKvuJDn1TzVuIIi\n9NmVasTjhZJ0PyWithWuZplo/LXUwSoid8HVyqe5ZVI=\n-----END CERTIFICATE REQUEST-----\n" # random email bad_email = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(6)) + '@gmail.com' email = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(6)) + '@' + website def test_invalid_phone(): # invalid phone r = provider_reg(email, '780w021-', name, org_id, csr)