Ejemplo n.º 1
0
    def test_validate_error(self):
        payload = (
            b'{'
            b'  "web": {'
            b'    "client_id": "[[CLIENT ID REQUIRED]]",'
            b'    "client_secret": "[[CLIENT SECRET REQUIRED]]",'
            b'    "redirect_uris": ["http://localhost:8080/oauth2callback"],'
            b'    "auth_uri": "",'
            b'    "token_uri": ""'
            b'  }'
            b'}')
        ERRORS = [
            ('{}', 'Invalid'),
            ('{"foo": {}}', 'Unknown'),
            ('{"web": {}}', 'Missing'),
            ('{"web": {"client_id": "dkkd"}}', 'Missing'),
            (payload, 'Property'),
        ]
        for src, match in ERRORS:
            # Ensure that it is unicode
            src = _from_bytes(src)
            # Test load(s)
            try:
                clientsecrets.loads(src)
                self.fail(src + ' should not be a valid client_secrets file.')
            except clientsecrets.InvalidClientSecretsError as e:
                self.assertTrue(str(e).startswith(match))

            # Test loads(fp)
            try:
                fp = StringIO(src)
                clientsecrets.load(fp)
                self.fail(src + ' should not be a valid client_secrets file.')
            except clientsecrets.InvalidClientSecretsError as e:
                self.assertTrue(str(e).startswith(match))
Ejemplo n.º 2
0
    def test_validate_error(self):
        payload = (
            b'{'
            b'  "web": {'
            b'    "client_id": "[[CLIENT ID REQUIRED]]",'
            b'    "client_secret": "[[CLIENT SECRET REQUIRED]]",'
            b'    "redirect_uris": ["http://localhost:8080/oauth2callback"],'
            b'    "auth_uri": "",'
            b'    "token_uri": ""'
            b'  }'
            b'}')
        ERRORS = [
            ('{}', 'Invalid'),
            ('{"foo": {}}', 'Unknown'),
            ('{"web": {}}', 'Missing'),
            ('{"web": {"client_id": "dkkd"}}', 'Missing'),
            (payload, 'Property'),
        ]
        for src, match in ERRORS:
            # Ensure that it is unicode
            src = _from_bytes(src)
            # Test load(s)
            try:
                clientsecrets.loads(src)
                self.fail(src + ' should not be a valid client_secrets file.')
            except clientsecrets.InvalidClientSecretsError as e:
                self.assertTrue(str(e).startswith(match))

            # Test loads(fp)
            try:
                fp = StringIO(src)
                clientsecrets.load(fp)
                self.fail(src + ' should not be a valid client_secrets file.')
            except clientsecrets.InvalidClientSecretsError as e:
                self.assertTrue(str(e).startswith(match))
Ejemplo n.º 3
0
  def test_validate_error(self):
    ERRORS = [
      ('{}', 'Invalid'),
      ('{"foo": {}}', 'Unknown'),
      ('{"web": {}}', 'Missing'),
      ('{"web": {"client_id": "dkkd"}}', 'Missing'),
      ("""{
         "web": {
           "client_id": "[[CLIENT ID REQUIRED]]",
           "client_secret": "[[CLIENT SECRET REQUIRED]]",
           "redirect_uris": ["http://localhost:8080/oauth2callback"],
           "auth_uri": "",
           "token_uri": ""
         }
       }
       """, 'Property'),
      ]
    for src, match in ERRORS:
      # Test load(s)
      try:
        clientsecrets.loads(src)
        self.fail(src + ' should not be a valid client_secrets file.')
      except clientsecrets.InvalidClientSecretsError, e:
        self.assertTrue(str(e).startswith(match))

      # Test loads(fp)
      try:
        fp = StringIO.StringIO(src)
        clientsecrets.load(fp)
        self.fail(src + ' should not be a valid client_secrets file.')
      except clientsecrets.InvalidClientSecretsError, e:
        self.assertTrue(str(e).startswith(match))
Ejemplo n.º 4
0
    def test_validate_error(self):
        payload = (
            b"{"
            b'  "web": {'
            b'    "client_id": "[[CLIENT ID REQUIRED]]",'
            b'    "client_secret": "[[CLIENT SECRET REQUIRED]]",'
            b'    "redirect_uris": ["http://localhost:8080/oauth2callback"],'
            b'    "auth_uri": "",'
            b'    "token_uri": ""'
            b"  }"
            b"}"
        )
        ERRORS = [
            ("{}", "Invalid"),
            ('{"foo": {}}', "Unknown"),
            ('{"web": {}}', "Missing"),
            ('{"web": {"client_id": "dkkd"}}', "Missing"),
            (payload, "Property"),
        ]
        for src, match in ERRORS:
            # Ensure that it is unicode
            src = _helpers._from_bytes(src)
            # Test load(s)
            with self.assertRaises(clientsecrets.InvalidClientSecretsError) as exc_manager:
                clientsecrets.loads(src)

            self.assertTrue(str(exc_manager.exception).startswith(match))

            # Test loads(fp)
            with self.assertRaises(clientsecrets.InvalidClientSecretsError) as exc_manager:
                fp = StringIO(src)
                clientsecrets.load(fp)

            self.assertTrue(str(exc_manager.exception).startswith(match))