#
# Copyright (c) SAS Institute Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


from testrunner import testhelp
from conary_test import rephelp

from conary_test import dbstoretest

from conary.repository import errors
from conary.repository.netrepos import netauth
from conary.repository.netrepos.auth_tokens import AuthToken
from conary.repository.netrepos.trovestore import TroveStore
from conary.server import schema
from conary import sqlite3
from conary import versions
from conary.deps import deps


class NetAuthTest(dbstoretest.DBStoreTestBase):

    def _setupDB(self):
        db = self.getDB()
        schema.createSchema(db)
        schema.setupTempTables(db)

        return db

    def _addUserRole(self, na, username, password):
        na.addRole(username)
        na.addUser(username, password)
        na.addRoleMember(username, username)
        
    def testManageAcls(self):
        db = self._setupDB()

        ts = TroveStore(db)
        na = netauth.NetworkAuthorization(db, "conary.rpath.com")

        authToken = ("testuser", "testpass", [ (None, None) ], None )
        self._addUserRole(na, "testuser", "testpass")
        na.addAcl("testuser", None, None, write = True)