Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot validate Redfish schemas from last redfish spec #610

Closed
frsauvage opened this issue Oct 9, 2019 · 7 comments
Closed

Cannot validate Redfish schemas from last redfish spec #610

frsauvage opened this issue Oct 9, 2019 · 7 comments

Comments

@frsauvage
Copy link

frsauvage commented Oct 9, 2019

Hi,
I cannot validate my simple Chassis schema with jsonschema.
I downloaded last redfish schemas DSP8010.
I tried to validate with :

mychassis.json

{
"@odata.type": "#Chassis.v1_7_0.Chassis",
"Id": "Rack_1",
"Name": "Sequana2 Rack",
"ChassisType": "Rack",
"Model": "Sequana 2 Ancien Rack",
"WeightKg": 123,
"WidthMm": 654,
"Manufacturer": "Bull",
"SerialNumber": "3M220100SL",
"PartNumber": "",
"PowerState": "On",
"@odata.context": "/redfish/v1/$metadata#Chassis.Chassis",
"@odata.id": "/redfish/v1/Chassis/Rack_1",
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
}

jsonschema -i mychassis.json jsonschema/Chassis.v1_7_0.json

Error:

File "/bin/jsonschema", line 11, in <module> sys.exit(main()) File "/usr/lib/python2.7/site-packages/jsonschema/cli.py", line 73, in main sys.exit(run(arguments=parse_args(args=args))) File "/usr/lib/python2.7/site-packages/jsonschema/cli.py", line 84, in run for error in validator.iter_errors(instance): File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 323, in iter_errors for error in errors: File "/usr/lib/python2.7/site-packages/jsonschema/_validators.py", line 263, in ref for error in validator.descend(instance, resolved): File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 339, in descend for error in self.iter_errors(instance, schema): File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 323, in iter_errors for error in errors: File "/usr/lib/python2.7/site-packages/jsonschema/_validators.py", line 286, in properties schema_path=property, File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 339, in descend for error in self.iter_errors(instance, schema): File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 323, in iter_errors for error in errors: File "/usr/lib/python2.7/site-packages/jsonschema/_validators.py", line 259, in ref scope, resolved = validator.resolver.resolve(ref) File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 734, in resolve return url, self._remote_cache(url) File "/usr/lib/python2.7/site-packages/functools32/functools32.py", line 400, in wrapper result = user_function(*args, **kwds) File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 744, in resolve_from_url raise exceptions.RefResolutionError(exc) jsonschema.exceptions.RefResolutionError: No JSON object could be decoded
Any suggestion?

Best Regards,
Francine

@Julian
Copy link
Member

Julian commented Oct 9, 2019

Hi, hard to answer this without a reproducible example (your schema at least).

That traceback is telling you it hit some URL and got back something that wasn't JSON, but beyond that impossible to tell without whatever you're running there (the schema).

@frsauvage
Copy link
Author

Hi Julian, I investigate a lot.
I git/clone jsonschema. I debug it. I put a breakpoint on jsonchema.compat.geturl (see below).
Weird.

Well, I have a proxy, i guess it could be the origin of this issue.

jsonschema httperror

There is an exception just after the breakpoint with HttpError 403 Forbidden (See attachement in the Visual Code terminal on the bottom when I use a terminal)

The url is accessible from a browser on the same machine.

Any idea ? I guess I will change geturl to request library.

Regards,
Francine

@Julian
Copy link
Member

Julian commented Oct 11, 2019

I don't see the relationship there between what you're breaking on -- the traceback is saying the URL it hit is returning a 403. Why it is returning a 403, or what URL is being hit and why (probably because you have a $ref in your schema?) is the question -- but, and apologies for this, the issue tracker isn't really the place for these sorts of things.

It's for bug reports or feature requests -- if you need some help debugging there are other channels where that help is more than welcome, though you still will likely need to provide the reproducible example for others to help. https://sscce.org is a good site if you want some guidelines on what that looks like. And the JSON Schema slack channel is probably your first bet on where specifically I think.

@Julian Julian closed this as completed Oct 11, 2019
@frsauvage
Copy link
Author

I finally understand:
Redfish site does NOT allow request without User-Agent Header.
I added in compat.py


    def urlopen(*args, **kwargs):
        url=args[0]
        req = urllib2.Request(url, headers= {'User-Agent': 'Mozilla/5.0'})
        url_open = urllib2.urlopen(req)
        return contextlib.closing(url_open) 

I guess you should take care of that :

Regards,
Francine

@Julian
Copy link
Member

Julian commented Oct 11, 2019

Are you sure that no header is being sent at all? I haven't looked in awhile, but very likely one is being sent, but the site you're talking to rejects scripting user agents. Changing it in the way you have likely evades their "ban" on scripting user agents since you effectively now have a user agent it doesn't know about or assumes might be a browser, but that's not something that jsonschema is going to change (either the site you're talking to doesn't want to be talked to in this way, which is something you need to check with the site owner, or its somehow misconfigured).

It's true that jsonschema should likely set its own user agent that indicates requests coming specifically from it, but spoofing that to be some user agent that looks like a browser isn't going to happen, it'd just be the python-requests user agent (or whatever HTTP library we use), with the additional info that it comes from jsonschema.

But yeah if you do find that no user agent header is being set at all that certainly should be fixed.

@frsauvage
Copy link
Author

Are you sure that no header is being sent at all?
@Julian
Yes, I swear :-) no "User-Agent" is sent. Adding it solve my issue definitely.
See https://stackoverflow.com/questions/38489386/python-requests-403-forbidden

I don't know why Redfish / DMTF site cares about it.

Thank you for your help and your reactivity,
Francine

@Julian
Copy link
Member

Julian commented Oct 16, 2019

jsonschema -i =(printf '""') =(printf '{"$ref": "http://localhost:8080/integer.json"}')

with a running webserver on 8080, and with requests installed, sends a user agent of: "python-requests/2.22.0" -- i.e. the default requests user agent.

Without requests (via urllib2), it sends: "Python-urllib/3.7", i.e. the default urllib user agent.

2019-10-16T16:30:00-0400 [twisted.python.log#info] "127.0.0.1" - - [16/Oct/2019:20:30:00 +0000] "GET /integer.json HTTP/1.1" 200 26 "-" "python-requests/2.22.0"
2019-10-16T16:34:36-0400 [twisted.python.log#info] "127.0.0.1" - - [16/Oct/2019:20:34:36 +0000] "GET /integer.json HTTP/1.1" 200 26 "-" "Python-urllib/3.7"

What are you seeing that tells you no User-Agent is being sent?

Julian added a commit that referenced this issue Nov 28, 2022
78c888273 Merge pull request #618 from json-schema-org/gregsdennis/contentschema-should-fail-content
5cbc53bc0 Merge pull request #613 from santhosh-tekuri/rjp-multidigit
bb000ce98 Merge pull request #620 from json-schema-org/ether/remove-unused-remotes
c4c490f1d Merge pull request #617 from json-schema-org/gregsdennis/dynamicAnchor-inside-propertyDependencies
0189831a9 remove schemas that are never referenced
cf1b94249 Merge pull request #610 from handrews/rm-remotes
d6490e817 move anchors into defs
2f9d117c0 Merge pull request #616 from json-schema-org/gregsdennis/propertyDependencies-and-unevaluated
4e5649cd0 move tests to draft-next
a41f2f6c4 added type:object to contentSchema schemas
2f50e7864 add tests for $dynamicAnchor in multiple branches of propertyDependencies
4794a1991 add tests for unevaluatedProperties seeing inside propertyDependencies
27cc299f3 Add RJP test 'multi-digit integer prefix'
716b95d94 Merge pull request #612 from santhosh-tekuri/rjp-positive
320c804d1 Add RJP test 'explicit positive prefix'
c8f210c39 Merge pull request #611 from santhosh-tekuri/time-alpha
3faeb222d add time test 'contains letters'
642441f2d Merge pull request #603 from santhosh-tekuri/uuid-nonstr
94d5043c7 add non-string uri tests
0c81374a2 Remove unneeded remotes
97a3e2156 Merge pull request #608 from json-schema-org/json-everything-uses-the-test-suite
bdaf7e8be added json-everything to 'who uses' section of readme; removed manatee.json (deprecated)
f00ec1008 Merge pull request #606 from santhosh-tekuri/duration-nounit
134480721 Merge pull request #607 from santhosh-tekuri/time-offsetprefix
dd4538eee Test time format 'offset not starting with plus or minus'
80fe2db15 test duration format 'element without unit'
38ea15116 Merge pull request #604 from santhosh-tekuri/time-offset
613ec170e second fraction, not offset
ee4bd4eb6 Add time format test with second fraction, no offset
86c2517cd Merge pull request #605 from santhosh-tekuri/rjp-empty
cfe80006a Add relative-json-pointer test with empty string
31796b3b8 add non-string uuid tests

git-subtree-dir: json
git-subtree-split: 78c8882732bcdc2dad81cd7ce1e3f9bca6fb7a9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants