kylef / JSONWebToken.swift

Swift implementation of JSON Web Token (JWT).
http://jwt.io
BSD 2-Clause "Simplified" License
763 stars 226 forks source link

testEncodingJWT Fails on iPhone 4S #22

Closed tternes closed 7 years ago

tternes commented 8 years ago

The testEncodingJWT test fails on iOS 8 (via Travis):

✗ testEncodingJWT, XCTAssertEqual failed: ("Optional("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiS3lsZSJ9.4tCpoxfyfjbUyLjm9_zu-r52Vxn6bFq9kp6Rt9xMs4A")") is not equal to ("Optional("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiS3lsZSJ9.zxm7xcp1eZtZhp4t-nlw09ATQnnFKIiSN83uG8u6cAg")") -

https://travis-ci.org/tternes/JSONWebToken.swift/jobs/105298771

tternes commented 8 years ago

This doesn't appear to be an OS issue, but possibly a 32/64 bit issue. The following test pass was done against iOS 9 with the same device (iPhone 4S) failing:

https://travis-ci.org/tternes/JSONWebToken.swift/jobs/105309981

florentmorin commented 8 years ago

JWT seems to use CryptoSwift, so it's probably due to a CryptoSwift issue.

kylef commented 8 years ago

I think it could well be a problem CryptoSwift, I haven't had chance to look into it and confirm. If anyone does I'd really appreciate it.

tternes commented 8 years ago

I think the problem boils down to the test assuming the order elements in the dictionary will be serialized - which happens to be different on different devices. For example, { "name" : "John", "age" : 27 } and { "age" : 27, "name" : "John" } are equivalent in terms of data, but their HMAC values will be very different, since the string versions are different.

I think this is probably a matter of pursuing a slightly different strategy for these tests.