def test_setupAuth(): testUserName = '******' # ensure setup with no details doesnt create file assert os.path.exists(Auth.config) is False assert Auth.SetupAuth(False) == (False, False) assert os.path.exists(Auth.config) is True assert Utils.ReadFile(Auth.config) == "{}" os.unlink(Auth.config) # create initial file assert os.path.exists(Auth.config) is False assert Auth.SetupAuth(False, testUserIds=['test']) == (False, False) assert os.path.exists(Auth.config) is True # ensure permissions are correct after creating config assert '0660' == oct(os.stat(Auth.config)[stat.ST_MODE])[-4:] # add dummy details storage = multistore_file.get_credential_storage( Auth.config, Auth.clientid, 'testuseraccount', ['https://www.googleapis.com/auth/cloudprint']) credentials = client.OAuth2Credentials( 'test', Auth.clientid, 'testsecret', 'testtoken', 1, 'https://www.googleapis.com/auth/cloudprint', testUserName) storage.put(credentials) # ensure permissions are correct after populating config assert '0660' == oct(os.stat(Auth.config)[stat.ST_MODE])[-4:] # re-run to test getting credentials requestors, storage = Auth.SetupAuth(False) assert requestors is not None assert storage is not None # check deleting account assert Auth.DeleteAccount(testUserName) is None requestors, storage = Auth.SetupAuth(False) assert requestors is False assert storage is False
def test_setupAuth(): # create initial file assert os.path.exists('/tmp/cloudprint.conf') == False assert Auth.SetupAuth(False) == False assert os.path.exists('/tmp/cloudprint.conf') == True # add dummy details storage = multistore_file.get_credential_storage( Auth.config, Auth.clientid, 'testuseraccount', ['https://www.googleapis.com/auth/cloudprint']) credentials = client.OAuth2Credentials( 'test', Auth.clientid, 'testsecret', 'testtoken', 1, 'https://www.googleapis.com/auth/cloudprint', 'testaccount1') storage.put(credentials) # re-run to test getting credentials requestors, storage = Auth.SetupAuth(False) assert requestors != None assert storage != None
def test_setupAuthOwnership(): assert Auth.SetupAuth(False, testUserIds=['test']) == (False, False) # ensure ownership is correct after creating config assert Utils.GetLPID() == os.stat(Auth.config).st_gid # add dummy details storage = multistore_file.get_credential_storage( Auth.config, Auth.clientid, 'testuseraccount', ['https://www.googleapis.com/auth/cloudprint']) credentials = client.OAuth2Credentials( 'test', Auth.clientid, 'testsecret', 'testtoken', 1, 'https://www.googleapis.com/auth/cloudprint', 'testaccount1') storage.put(credentials) # ensure ownership is correct after populating config assert Utils.GetLPID() == os.stat(Auth.config).st_gid
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. if __name__ == '__main__': # pragma: no cover import sys from auth import Auth from printermanager import PrinterManager from ccputils import Utils Utils.SetupLogging() # line below is replaced on commit CCPVersion = "20140501 203545" Utils.ShowVersion(CCPVersion) requestors, storage = Auth.SetupAuth(True) printer_manager = PrinterManager(requestors) printers = printer_manager.getPrinters() if printers is None: print "No Printers Found" sys.exit(1) for printer in printers: print printer.getListDescription()
sys.path.insert(0, libpath) from auth import Auth from printermanager import PrinterManager from ccputils import Utils if len(sys.argv) < 2: showUsage() Utils.SetupLogging() # line below is replaced on commit CCPVersion = "20140607 101641" Utils.ShowVersion(CCPVersion) requestors, storage = Auth.SetupAuth(False) if not requestors: sys.stderr.write("ERROR: config is invalid or missing\n") logging.error("backend tried to run with invalid config") sys.exit(1) printer_manager = PrinterManager(requestors) if sys.argv[1] == 'list': doList(sys, printer_manager) elif sys.argv[1] == 'cat': if len(sys.argv) == 2 or sys.argv[2] == "": showUsage() doCat()
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import cups, os, json, sys from auth import Auth from printer import Printer if len(sys.argv) == 2 and sys.argv[1] == 'version': # line below is replaced on commit CCPVersion = "20131017 220257" print "CUPS Cloud Print Delete Account Script Version " + CCPVersion sys.exit(0) while True: result = Auth.SetupAuth(False) if not result: print("No accounts are currently setup") break else: requestors, storage = result print("You currently have these accounts configured: ") i = 0 accounts = [] for requestor in requestors: i += 1 accounts.append(requestor.getAccount()) print(str(i) + ") " + requestor.getAccount()) print("0) Exit") answer = raw_input("Which account to delete (1-" + str(i) + ") ? ") if (answer.isdigit() and int(answer) <= i and int(answer) >= 1):
if __name__ == '__main__': # pragma: no cover import sys sys.path.insert(0, ".") from auth import Auth from ccputils import Utils Utils.SetupLogging() # line below is replaced on commit CCPVersion = "20140606 220318" Utils.ShowVersion(CCPVersion) requestors, storage = Auth.SetupAuth( True, permissions=[ 'https://www.googleapis.com/auth/cloudprint', 'https://www.googleapis.com/auth/drive.readonly' ]) files = getDriveFiles(requestors) if files is None: print "No Files Found" sys.exit(1) for drivefile in files: if len(sys.argv) == 2 and drivefile['title'] == sys.argv[1] + '.pdf': print drivefile['fileSize'] sys.exit(0) elif len(sys.argv) != 2: print drivefile['title']
def test_setupAuthInteractive(): # ensure running setup in interactive mode tries to read stdin with pytest.raises(IOError): Auth.SetupAuth(True)
if __name__ == '__main__': # pragma: no cover import cups, os, json, sys, logging from auth import Auth from printer import Printer if len(sys.argv) == 2 and sys.argv[1] == 'version': # line below is replaced on commit CCPVersion = "20140223 234321" print "CUPS Cloud Print Delete Account Script Version " + CCPVersion sys.exit(0) from ccputils import Utils Utils.SetupLogging() while True: result, storage = Auth.SetupAuth(False) if not result: print "No accounts are currently setup" break else: requestors = result print "You currently have these accounts configured: " i = 0 accounts = [] for requestor in requestors: i += 1 accounts.append(requestor.getAccount()) print str(i) + ") " + requestor.getAccount() print "0) Exit" answer = raw_input("Which account to delete (1-" + str(i) + ") ? ") if (answer.isdigit() and int(answer) <= i and int(answer) >= 1):
def resetAccounts(self): self.requestors, self.auth_storage = Auth.SetupAuth(False) self._ccp_printers = None
except Exception as e: sys.stderr.write("Could not connect to CUPS: " + e.message + "\n") sys.exit(0) if os.path.exists(Auth.config): try: content_file = open(Auth.config, 'r') content = content_file.read() data = json.loads(content) except Exception: # remove old config file print "Deleting old configuration file: " + Auth.config os.remove(Auth.config) while True: requestors, storage = Auth.SetupAuth(interactive=False) if storage is not False: print "You currently have these accounts configured: " for requestor in requestors: print requestor.getAccount() add_account = len(requestors) == 0 else: add_account = True if not add_account: if not options.interactive: break answer = raw_input("Add more accounts (Y/N)? ") if answer.lower().startswith("y"): add_account = True else: break