'Test creating trust scoped ec2 credential.
Call ``POST /credentials``.'

def test_trust_scoped_ec2_credential(self):

    ref = unit.new_trust_ref(trustor_user_id=self.user_id, trustee_user_id=self.trustee_user_id, project_id=self.project_id, impersonation=True, expires=dict(minutes=1), role_ids=[self.role_id])
    del ref['id']
    r = self.post('/OS-TRUST/trusts', body={'trust': ref})
    trust = self.assertValidTrustResponse(r)
    auth_data = self.build_authentication_request(user_id=self.trustee_user['id'], password=self.trustee_user['password'], trust_id=trust['id'])
    r = self.v3_create_token(auth_data)
    self.assertValidProjectScopedTokenResponse(r, self.user)
    trust_id = r.result['token']['OS-TRUST:trust']['id']
    token_id = r.headers.get('X-Subject-Token')
    (blob, ref) = unit.new_ec2_credential(user_id=self.user['id'], project_id=self.project_id)
    r = self.post('/credentials', body={'credential': ref}, token=token_id)
    ret_ref = ref.copy()
    ret_blob = blob.copy()
    ret_blob['trust_id'] = trust_id
    ret_ref['blob'] = json.dumps(ret_blob)
    self.assertValidCredentialResponse(r, ref=ret_ref)
    access = blob['access'].encode('utf-8')
    self.assertEqual(hashlib.sha256(access).hexdigest(), r.result['credential']['id'])
    self.post('/credentials', body={'credential': ref}, token=token_id, expected_status=http_client.CONFLICT)
