<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import sys <EOL> from salt . ext . six . moves import map <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> import unittest2 as unittest <EOL> else : <EOL> import unittest <EOL> import os <EOL> import stat <EOL> import time <EOL> import tempfile <EOL> import shutil <EOL> from ioflo . aid . odicting import odict <EOL> from ioflo . aid . timing import Timer , StoreTimer <EOL> from ioflo . base import storing <EOL> from ioflo . base . consoling import getConsole <EOL> console = getConsole ( ) <EOL> from raet import raeting , nacling <EOL> from raet . road import estating , keeping , stacking <EOL> from salt . key import RaetKey <EOL> def setUpModule ( ) : <EOL> console . reinit ( verbosity = console . Wordage . concise ) <EOL> def tearDownModule ( ) : <EOL> pass <EOL> class BasicTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . store = storing . Store ( stamp = <NUM_LIT:0.0> ) <EOL> self . timer = StoreTimer ( store = self . store , duration = <NUM_LIT:1.0> ) <EOL> self . saltDirpath = tempfile . mkdtemp ( prefix = "<STR_LIT>" , suffix = "<STR_LIT>" , dir = '<STR_LIT>' ) <EOL> pkiDirpath = os . path . join ( self . saltDirpath , '<STR_LIT>' ) <EOL> if not os . path . exists ( pkiDirpath ) : <EOL> os . makedirs ( pkiDirpath ) <EOL> acceptedDirpath = os . path . join ( pkiDirpath , '<STR_LIT>' ) <EOL> if not os . path . exists ( acceptedDirpath ) : <EOL> os . makedirs ( acceptedDirpath ) <EOL> pendingDirpath = os . path . join ( pkiDirpath , '<STR_LIT>' ) <EOL> if not os . path . exists ( pendingDirpath ) : <EOL> os . makedirs ( pendingDirpath ) <EOL> rejectedDirpath = os . path . join ( pkiDirpath , '<STR_LIT>' ) <EOL> if not os . path . exists ( rejectedDirpath ) : <EOL> os . makedirs ( rejectedDirpath ) <EOL> self . localFilepath = os . path . join ( pkiDirpath , '<STR_LIT>' ) <EOL> if os . path . exists ( self . localFilepath ) : <EOL> mode = os . stat ( self . localFilepath ) . st_mode <EOL> os . chmod ( self . localFilepath , mode | stat . S_IWUSR | stat . S_IWUSR ) <EOL> self . cacheDirpath = os . path . join ( self . saltDirpath , '<STR_LIT>' ) <EOL> self . sockDirpath = os . path . join ( self . saltDirpath , '<STR_LIT>' ) <EOL> self . opts = dict ( <EOL> __role = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> pki_dir = pkiDirpath , <EOL> sock_dir = self . sockDirpath , <EOL> cachedir = self . cacheDirpath , <EOL> open_mode = False , <EOL> auto_accept = True , <EOL> transport = '<STR_LIT>' , <EOL> ) <EOL> self . mainKeeper = RaetKey ( opts = self . opts ) <EOL> self . baseDirpath = tempfile . mkdtemp ( prefix = "<STR_LIT>" , suffix = "<STR_LIT>" , dir = '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> if os . path . exists ( self . saltDirpath ) : <EOL> shutil . rmtree ( self . saltDirpath ) <EOL> def createRoadData ( self , name , base ) : <EOL> '''<STR_LIT>''' <EOL> data = odict ( ) <EOL> data [ '<STR_LIT:name>' ] = name <EOL> data [ '<STR_LIT>' ] = os . path . join ( base , '<STR_LIT>' , '<STR_LIT>' , name ) <EOL> signer = nacling . Signer ( ) <EOL> data [ '<STR_LIT>' ] = signer . keyhex <EOL> data [ '<STR_LIT>' ] = signer . verhex <EOL> privateer = nacling . Privateer ( ) <EOL> data [ '<STR_LIT>' ] = privateer . keyhex <EOL> data [ '<STR_LIT>' ] = privateer . pubhex <EOL> return data <EOL> def testAutoAccept ( self ) : <EOL> '''<STR_LIT>''' <EOL> console . terse ( "<STR_LIT>" . format ( self . testAutoAccept . __doc__ ) ) <EOL> self . opts [ '<STR_LIT>' ] = True <EOL> self . assertTrue ( self . opts [ '<STR_LIT>' ] ) <EOL> self . assertDictEqual ( self . mainKeeper . all_keys ( ) , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { } ) <EOL> main = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> self . mainKeeper . write_local ( main [ '<STR_LIT>' ] , main [ '<STR_LIT>' ] ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { '<STR_LIT>' : main [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : main [ '<STR_LIT>' ] } ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> other1 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> other2 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> status = self . mainKeeper . status ( other1 [ '<STR_LIT:name>' ] , other1 [ '<STR_LIT>' ] , other1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> status = self . mainKeeper . status ( other2 [ '<STR_LIT:name>' ] , other2 [ '<STR_LIT>' ] , other2 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other1 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other2 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] } ) <EOL> listkeys = self . mainKeeper . list_keys ( ) <EOL> self . assertDictEqual ( listkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> allremotekeys = self . mainKeeper . read_all_remote ( ) <EOL> self . assertDictEqual ( allremotekeys , { '<STR_LIT>' : <EOL> { '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , } <EOL> } ) <EOL> def testManualAccept ( self ) : <EOL> '''<STR_LIT>''' <EOL> console . terse ( "<STR_LIT>" . format ( self . testAutoAccept . __doc__ ) ) <EOL> self . opts [ '<STR_LIT>' ] = False <EOL> self . assertFalse ( self . opts [ '<STR_LIT>' ] ) <EOL> self . assertDictEqual ( self . mainKeeper . all_keys ( ) , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { } ) <EOL> main = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> self . mainKeeper . write_local ( main [ '<STR_LIT>' ] , main [ '<STR_LIT>' ] ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { '<STR_LIT>' : main [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : main [ '<STR_LIT>' ] } ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> other1 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> other2 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> status = self . mainKeeper . status ( other1 [ '<STR_LIT:name>' ] , other1 [ '<STR_LIT>' ] , other1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> status = self . mainKeeper . status ( other2 [ '<STR_LIT:name>' ] , other2 [ '<STR_LIT>' ] , other2 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other1 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other2 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { } ) <EOL> listkeys = self . mainKeeper . list_keys ( ) <EOL> self . assertDictEqual ( listkeys , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ) <EOL> allremotekeys = self . mainKeeper . read_all_remote ( ) <EOL> self . assertDictEqual ( allremotekeys , { '<STR_LIT>' : <EOL> { '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , } <EOL> } ) <EOL> self . mainKeeper . accept_all ( ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other1 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other2 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] } ) <EOL> listkeys = self . mainKeeper . list_keys ( ) <EOL> self . assertDictEqual ( listkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> allremotekeys = self . mainKeeper . read_all_remote ( ) <EOL> self . assertDictEqual ( allremotekeys , { '<STR_LIT>' : <EOL> { '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , } <EOL> } ) <EOL> def testDelete ( self ) : <EOL> '''<STR_LIT>''' <EOL> console . terse ( "<STR_LIT>" . format ( self . testDelete . __doc__ ) ) <EOL> self . opts [ '<STR_LIT>' ] = True <EOL> self . assertTrue ( self . opts [ '<STR_LIT>' ] ) <EOL> self . assertDictEqual ( self . mainKeeper . all_keys ( ) , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { } ) <EOL> main = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> self . mainKeeper . write_local ( main [ '<STR_LIT>' ] , main [ '<STR_LIT>' ] ) <EOL> localkeys = self . mainKeeper . read_local ( ) <EOL> self . assertDictEqual ( localkeys , { '<STR_LIT>' : main [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : main [ '<STR_LIT>' ] } ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> other1 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> other2 = self . createRoadData ( name = '<STR_LIT>' , base = self . baseDirpath ) <EOL> status = self . mainKeeper . status ( other1 [ '<STR_LIT:name>' ] , other1 [ '<STR_LIT>' ] , other1 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> status = self . mainKeeper . status ( other2 [ '<STR_LIT:name>' ] , other2 [ '<STR_LIT>' ] , other2 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( status , '<STR_LIT>' ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other1 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other2 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] } ) <EOL> listkeys = self . mainKeeper . list_keys ( ) <EOL> self . assertDictEqual ( listkeys , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> allremotekeys = self . mainKeeper . read_all_remote ( ) <EOL> self . assertDictEqual ( allremotekeys , { '<STR_LIT>' : <EOL> { '<STR_LIT>' : other1 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other1 [ '<STR_LIT>' ] } , <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , } <EOL> } ) <EOL> self . mainKeeper . delete_key ( match = other1 [ '<STR_LIT:name>' ] ) <EOL> allkeys = self . mainKeeper . all_keys ( ) <EOL> self . assertDictEqual ( allkeys , { '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ self . localFilepath ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other1 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { } ) <EOL> remotekeys = self . mainKeeper . read_remote ( other2 [ '<STR_LIT:name>' ] ) <EOL> self . assertDictEqual ( remotekeys , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] } ) <EOL> listkeys = self . mainKeeper . list_keys ( ) <EOL> self . assertDictEqual ( listkeys , { '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] } ) <EOL> allremotekeys = self . mainKeeper . read_all_remote ( ) <EOL> self . assertDictEqual ( allremotekeys , { <EOL> '<STR_LIT>' : <EOL> { '<STR_LIT>' : other2 [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : other2 [ '<STR_LIT>' ] , } <EOL> } ) <EOL> def runOne ( test ) : <EOL> '''<STR_LIT>''' <EOL> test = BasicTestCase ( test ) <EOL> suite = unittest . TestSuite ( [ test ] ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) <EOL> def runSome ( ) : <EOL> '''<STR_LIT>''' <EOL> tests = [ ] <EOL> names = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> tests . extend ( list ( list ( map ( BasicTestCase , names ) ) ) ) <EOL> suite = unittest . TestSuite ( tests ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) <EOL> def runAll ( ) : <EOL> '''<STR_LIT>''' <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . TestLoader ( ) . loadTestsFromTestCase ( BasicTestCase ) ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) <EOL> if __name__ == '<STR_LIT:__main__>' and __package__ is None : <EOL> runAll ( ) </s>
