This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
/
simple_auth.py
87 lines (79 loc) · 2.56 KB
/
simple_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import string
import random
import os
import sys
import nose.tools
import boto
from boto.s3.connection import OrdinaryCallingFormat
from boto.s3.connection import VHostCallingFormat
from boto.s3.connection import SubdomainCallingFormat
import sys
from ConfigParser import SafeConfigParser
from pycb.cumulus import *
import time
import pycb.test_common
import unittest
import tempfile
import filecmp
#
class TestBucketsWithBoto(unittest.TestCase):
def setUp(self):
(self.host, self.port) = pycb.test_common.get_contact()
self.user_id_list = []
def tearDown(self):
for (id, pw) in self.user_id_list:
self.clean_all(id, pw)
pycb.test_common.clean_user(id)
pass
def make_user(self):
# note this only works if access to the same FS
(id, pw) = pycb.test_common.make_user()
self.user_id_list.append([id, pw])
return (id, pw)
def clean_all(self, id, pw):
print "clean %s : %s" % (id, pw)
conn5 = pycb.test_common.cb_get_conn(self.host, self.port, id, pw)
nbs = conn5.get_all_buckets()
for b in nbs:
rs = b.list()
for key in rs:
try:
key.delete()
except:
pass
try:
b.delete()
except:
pass
def cb_random_bucketname(self, len):
chars = string.letters + string.digits
newpasswd = ""
for i in range(len):
newpasswd = newpasswd + random.choice(chars)
return newpasswd
def create_bucket(self, conn):
done = False
count = 0
while done == False:
bucketname = self.cb_random_bucketname(10)
try:
bucket = conn.create_bucket(bucketname)
done = True
except Exception, ex:
print ex
print sys.exc_info()[0]
print "bucket name %s exists, trying again" % (bucketname)
done = False
count = count + 1
if count > 10:
done = True
print "could not make bucket in many trys"
raise
return (bucketname, bucket)
def test_bucket_perm_simple(self):
(id, pw) = self.make_user()
(id2, pw2) = self.make_user()
conn = pycb.test_common.cb_get_conn(self.host, self.port, id, pw)
nbs = conn.get_all_buckets()
conn2 = pycb.test_common.cb_get_conn(self.host, self.port, id, pw)
nbs2 = conn.get_all_buckets()