'Test token authentication for Fernet token provider.
Verify that token authentication returns validate response code and
valid token belongs to project.'

def test_token_authentication_and_validation(self):

    project_ref = self.new_project_ref()
    self.resource_api.create_project(project_ref['id'], project_ref)
    unscoped_token = self.get_unscoped_token()
    self.assignment_api.add_role_to_user_and_project(self.user_foo['id'], project_ref['id'], self.role_admin['id'])
    token_id = unscoped_token
    if six.PY2:
        token_id = token_id.encode('ascii')
    r = self.public_request(method='POST', path='/v2.0/tokens', body={'auth': {'tenantName': project_ref['name'], 'token': {'id': token_id}}}, expected_status=http_client.OK)
    token_id = self._get_token_id(r)
    path = ('/v2.0/tokens/%s?belongsTo=%s' % (token_id, project_ref['id']))
    resp = self.admin_request(method='GET', path=path, token=self.get_admin_token(), expected_status=http_client.OK)
    self.assertValidScopedTokenResponse(resp)
