Beispiel #1
0
 def test_find_airport_password(self):
     system_keychain = Keychain("/Library/Keychains/System.keychain")
     try:
         system_keychain.find_generic_password(account_name="linksys")
     except KeyError:
         print >> sys.stderr, "test_find_airport_password: assuming the non-existence of linksys SSID is correct"
         pass
 def test_find_airport_password(self):
     system_keychain = Keychain("/Library/Keychains/System.keychain")
     try:
         system_keychain.find_generic_password(account_name="linksys")
     except KeyError:
         print >> sys.stderr, "test_find_airport_password: assuming the non-existence of linksys SSID is correct"
         pass
    def test_find_internet_password(self):
        keychain = Keychain()
        i = keychain.find_internet_password(
            server_name="connect.apple.com"
        )  # BUG: Most people probably have this - but not everyone?

        self.failIfEqual(i, None)
def main():
    parser = OptionParser(__doc__.strip())

    parser.add_option('-a', '--account', '--account-name',
        help="Set the account name"
    )

    parser.add_option('-s', '--service', '--service-name',
        help="Set the service name"
    )

    parser.add_option('-k', '--keychain',
        help="Path to the keychain file"
    )

    (options, args) = parser.parse_args()

    if not options.keychain and os.getuid() == 0:
        options.keychain = "/Library/Keychains/System.keychain"

    if not (options.account or options.service):
        parser.error("You must specify either an account or service name")

    try:
        keychain = Keychain(options.keychain)
        item = keychain.find_generic_password(
            service_name=options.service,
            account_name=options.account
        )

        print "Removing %s" % item
        keychain.remove(item)
    except KeyError, exc:
        print >>sys.stderr, exc.message
        sys.exit(0)
Beispiel #5
0
    def test_add_and_remove_internet_password(self):
        import uuid
        k = Keychain()
        kwargs = {
            'server_name': "pymacadmin.googlecode.com",
            'account_name': "unittest",
            'protocol_type': 'http',
            'authentication_type': 'http',
            'password': str(uuid.uuid4())
        }

        i = InternetPassword(**kwargs)
        k.add(i)

        self.assertEquals(
            i.password,
            k.find_internet_password(
                server_name=kwargs['server_name'],
                account_name=kwargs['account_name']).password)

        k.remove(i)
        self.assertRaises(
            KeyError, k.find_internet_password, **{
                "server_name": kwargs['server_name'],
                "account_name": kwargs['account_name']
            })
def main():
    if len(sys.argv) < 3:
        print >> sys.stderr, __doc__.strip()
        sys.exit(1)

    ssid, new_password = sys.argv[1:3]

    if os.getuid() == 0:
        keychain = Keychain("/Library/Keychains/System.keychain")
    else:
        keychain = Keychain()

    try:
        item = keychain.find_generic_password(account_name=ssid)
        if item.password != new_password:
            item.update_password(new_password)

    except RuntimeError, exc:
        print >> sys.stderr, "Unable to change password for Airport network %s: %s" % (ssid, exc)
        sys.exit(1)
Beispiel #7
0
def main():
    if len(sys.argv) < 3:
        print >> sys.stderr, __doc__.strip()
        sys.exit(1)

    ssid, new_password = sys.argv[1:3]

    if os.getuid() == 0:
        keychain = Keychain("/Library/Keychains/System.keychain")
    else:
        keychain = Keychain()

    try:
        item = keychain.find_generic_password(account_name=ssid)
        if item.password != new_password:
            item.update_password(new_password)

    except RuntimeError, exc:
        print >> sys.stderr, "Unable to change password for Airport network %s: %s" % (
            ssid, exc)
        sys.exit(1)
    def test_add_and_remove_internet_password(self):
        import uuid

        k = Keychain()
        kwargs = {
            "server_name": "pymacadmin.googlecode.com",
            "account_name": "unittest",
            "protocol_type": "http",
            "authentication_type": "http",
            "password": str(uuid.uuid4()),
        }

        i = InternetPassword(**kwargs)
        k.add(i)

        self.assertEquals(
            i.password,
            k.find_internet_password(server_name=kwargs["server_name"], account_name=kwargs["account_name"]).password,
        )

        k.remove(i)
        self.assertRaises(
            KeyError,
            k.find_internet_password,
            **{"server_name": kwargs["server_name"], "account_name": kwargs["account_name"]}
        )
Beispiel #9
0
 def test_add_and_remove_generic_password(self):
     import uuid
     k            = Keychain()
     service_name = "PyMacAdmin Keychain Unit Test"
     account_name = str(uuid.uuid4())
     password     = str(uuid.uuid4())
     
     i = GenericPassword(service_name=service_name, account_name=account_name, password=password)
     k.add(i)
     self.assertEquals(i.password, k.find_generic_password(service_name, account_name).password)
     
     k.remove(i)
     self.assertRaises(KeyError, k.find_generic_password, **{"service_name": service_name, "account_name": account_name})
Beispiel #10
0
    def test_add_and_remove_generic_password(self):
        import uuid
        k = Keychain()
        service_name = "PyMacAdmin Keychain Unit Test"
        account_name = str(uuid.uuid4())
        password = str(uuid.uuid4())

        i = GenericPassword(service_name=service_name,
                            account_name=account_name,
                            password=password)

        k.add(i)

        self.assertEquals(
            i.password,
            k.find_generic_password(service_name, account_name).password)

        k.remove(i)
        self.assertRaises(
            KeyError, k.find_generic_password, **{
                "service_name": service_name,
                "account_name": account_name
            })
 def test_find_internet_password(self):
     keychain = Keychain()
     i = keychain.find_internet_password(server_name="connect.apple.com")
     self.failIfEqual(i, None)
Beispiel #12
0
 def test_find_airport_password(self):
     system_keychain = Keychain("/Library/Keychains/System.keychain")
     system_keychain.find_generic_password(account_name="linksys") # BUG: Most people probably have this - but not everyone?
Beispiel #13
0
 def test_find_internet_password(self):
     keychain = Keychain()
     i = keychain.find_internet_password(server_name="connect.apple.com")
     self.failIfEqual(i, None)
Beispiel #14
0
 def test_find_nonexistent_generic_password(self):
     import uuid
     system_keychain = Keychain("/Library/Keychains/System.keychain")
     self.assertRaises(
         KeyError, system_keychain.find_generic_password,
         **{'account_name': "NonExistantGenericPassword-%s" % uuid.uuid4()})
Beispiel #15
0
 def test_load_system_keychain(self):
     k = Keychain('/Library/Keychains/System.keychain')
     self.failIfEqual(k, None)
Beispiel #16
0
 def test_load_default_keychain(self):
     k = Keychain()
     self.failIfEqual(k, None)