Beispiel #1
0
def test_not_expired():
    isExpired = subject.isExpired("""
          {
            "version":1,
            "scopes":["*"],
            "start":1450740520182,
            "expiry":2451000620182,
            "seed":"90PyTwYxS96-lBPc0f_MqQGV-hHCUsTYWpXZilv6EqDg",
            "signature":"HocA2IiCoGzjUQZbrbLSwKMXZSYWCu/hfMPCa/ovggQ="
          }
        """)
    assert isExpired is False

    def test_expired(self):
        # Warning we have to test with expiry: 0 as magic python spy thing
        # mess up time.time() so it won't work.
        isExpired = subject.isExpired("""
            {
                "version":1,
                "scopes":["*"],
                "start":1450740520182,
                "expiry":0,
                "seed":"90PyTwYxS96-lBPc0f_MqQGV-hHCUsTYWpXZilv6EqDg",
                "signature":"HocA2IiCoGzjUQZbrbLSwKMXZSYWCu/hfMPCa/ovggQ="
            }
            """)
        assert isExpired is True
Beispiel #2
0
def tc_authenticate(logger):
    """
    Returns valid credentials for use with Taskcluster private builds.
    """
    # first, try to load credentials from mozregression config file
    defaults = get_defaults(DEFAULT_CONF_FNAME)
    client_id = defaults.get('taskcluster-clientid')
    access_token = defaults.get('taskcluster-accesstoken')
    if client_id and access_token:
        return dict(clientId=client_id, accessToken=access_token)

    try:
        # else, try to load a valid certificate locally
        with open(TC_CREDENTIALS_FNAME) as f:
            creds = json.load(f)
        if not tc_utils.isExpired(creds['certificate']):
            return creds
    except Exception:
        pass

    # here we need to ask for a certificate, this require web browser
    # authentication
    logger.info(
        "Authentication required from taskcluster. We are going to ask for a"
        " certificate.\nNote that if you have long term access you can instead"
        " set your taskcluster-clientid and taskcluster-accesstoken in the"
        " configuration file (%s)." % DEFAULT_CONF_FNAME)
    creds = tc_utils.authenticate("mozregression private build access")

    # save the credentials and the certificate for later use
    with open(TC_CREDENTIALS_FNAME, 'w') as f:
        json.dump(creds, f)
    return creds
Beispiel #3
0
 def test_not_expired(self):
     isExpired = subject.isExpired("""
       {
         "version":1,
         "scopes":["*"],
         "start":1450740520182,
         "expiry":2451000620182,
         "seed":"90PyTwYxS96-lBPc0f_MqQGV-hHCUsTYWpXZilv6EqDg",
         "signature":"HocA2IiCoGzjUQZbrbLSwKMXZSYWCu/hfMPCa/ovggQ="
       }
     """)
     self.assertEqual(isExpired, False)
 def test_not_expired(self):
     isExpired = subject.isExpired("""
       {
         "version":1,
         "scopes":["*"],
         "start":1450740520182,
         "expiry":2451000620182,
         "seed":"90PyTwYxS96-lBPc0f_MqQGV-hHCUsTYWpXZilv6EqDg",
         "signature":"HocA2IiCoGzjUQZbrbLSwKMXZSYWCu/hfMPCa/ovggQ="
       }
     """)
     self.assertEqual(isExpired, False)
 def test_expired(self):
     # Warning we have to test with expiry: 0 as magic python spy thing
     # mess up time.time() so it won't work.
     isExpired = subject.isExpired("""
       {
         "version":1,
         "scopes":["*"],
         "start":1450740520182,
         "expiry":0,
         "seed":"90PyTwYxS96-lBPc0f_MqQGV-hHCUsTYWpXZilv6EqDg",
         "signature":"HocA2IiCoGzjUQZbrbLSwKMXZSYWCu/hfMPCa/ovggQ="
       }
     """)
     self.assertEqual(isExpired, True)