Beispiel #1
0
def test5_marshalAndParseJSON():
    """Test 5 creates a macaroon and tests the marshal and parse to JSON functions
    """
    printTestDesc("marshalToJSON")
    id = "abc"
    key = "234324"
    location = "DC"
    M = mlib.CreateMacaroon(key, id, location)
    caveat_cid = "123"
    caveat_vid = "0"
    caveat_cl = "NYC"
    M.addCaveatHelper(caveat_cid , caveat_vid,  caveat_cl)
    json_string = mlib.marshalToJSON(M)
    print(json_string)
    printTestDesc("parseToJSON")
    M_returned = mlib.parseFromJSON(json_string)
    #assert(M == M_returned)
    for key in M.__dict__.keys():
        object_of_M = M.__dict__[key]
        object_of_M_returned = M_returned.__dict__[key]
        print(key, object_of_M)
        if(type(object_of_M) == type([])):#list of strings
            assert(set(object_of_M) == set(object_of_M_returned))
        else:#string type
            assert(object_of_M_returned == object_of_M)
    #print(M_returned)
    printTestResult("test5_marshalAndParseJSON" , "SUCCESS")
Beispiel #2
0
def test3_addCaveatHelper():
    """Test 3 creates a simple macaroon and tests the caveat helper function
    """
    printTestDesc("addCaveatHelper")
    id = "abc"
    key = "234324"
    location = "DC"
    M = mlib.CreateMacaroon(key, id, location)
    global oldMacaroonCopy
    oldMacaroonCopy = mlib.parseFromJSON(mlib.marshalToJSON(M))
    assert(M.sig == oldMacaroonCopy.sig)
    caveat_cid = "123"
    caveat_vid = "sdfd"
    caveat_cl = "NYC"
    ## test addCaveatHelper
    M.addCaveatHelper(caveat_cid , caveat_vid,  caveat_cl)
    assert(M.sig != oldMacaroonCopy.sig)
    #### what to verify 
    #### test if the caveat was properly added 
    string_caveat = caveat_cid + ":" + caveat_vid + ":" + caveat_cl 
    assert(M.caveats[-1] == string_caveat)
    #### test if the caveat signature "evolved" correctly
    new_sig = hmac.new(oldMacaroonCopy.sig, caveat_vid+caveat_cid , hashlib.sha256)
    assert(M.sig == new_sig.hexdigest())
    printTestResult("addCaveatHelper" , "SUCCESS")
Beispiel #3
0
    #print(M.sig)
    #print(hmac_value_digest)
    printTestDesc("CreateMacaroon")
    assert(M.sig == hmac_value_digest)
    assert(M.id == id)
    printTestResult("CreateMacaroon" , "SUCCESS")

def test3_addCaveatHelper():
	"""Test 3 creates a simple macaroon and tests the caveat helper function
	"""
    printTestDesc("addCaveatHelper")
    id = "abc"
    key = "234324"
    location = "DC"
    M = mlib.CreateMacaroon(key, id, location)
    oldMacaroonCopy = mlib.parseFromJSON(mlib.marshalToJSON(M))
    assert(M.sig == oldMacaroonCopy.sig)
    caveat_cid = "123"
    caveat_vid = "sdfd"
    caveat_cl = "NYC"
    ## test addCaveatHelper
    M.addCaveatHelper(caveat_cid , caveat_vid,  caveat_cl)
    assert(M.sig != oldMacaroonCopy.sig)
    #### what to verify 
    #### test if the caveat was properly added 
    string_caveat = caveat_cid + ":" + caveat_vid + ":" + caveat_cl 
    assert(M.caveats[-1] == string_caveat)
    #### test if the caveat signature "evolved" correctly
    new_sig = hmac.new(oldMacaroonCopy.sig, caveat_vid+caveat_cid , hashlib.sha256)
    assert(M.sig == new_sig.hexdigest())
    printTestResult("addCaveatHelper" , "SUCCESS")