jwtPS
jwtPS copied to clipboard
Object cycle detected when running New-Jwt (JSON Serialize issue)
There is some issue with JSON Serialize that happens when i try New-Jwt. I receive the following error:
Line |
53 | $jwt = New-JWT -Payload $payload -Algorithm $alg -Secret $key
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than
| the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support
| cycles. Path:
| $.Members.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.OverloadDefinitions.
Here's the snippet:
$payload = [Ordered]@{
"iat" = ([System.DateTimeOffset]::Now).ToUnixTimeSeconds()
"kid" = $islkid
"hsig" = hashSha256($method + "|" + $webtoken)
"data" = $data | ConvertTo-Json
}
$encryption = [jwtTypes+encryption]::SHA256
$algorithm = [jwtTypes+algorithm]::RSA
$alg = [jwtTypes+cryptographyType]::new($algorithm, $encryption)
$jwt = New-JWT -Payload $payload -Algorithm $alg -Secret $key
return $jwt
I checked the payload in case there was something strange, but it looks OK:
[iat, 1673873422]
[kid, \\default\a]
[hsig, <hash_value>]
[data, {}]
How can I resolve this error?
Could you give an example of how to reproduce this?
Hi, simplest example.
it.only('add new todo', () => {
cy.matchImageSnapshot(); <-------------------------- First snapshot
cy.get('[data-test=new-todo]').type(`test{enter}`)
cy.matchImageSnapshot(); <-------------------------- Second snapshot
})
before I used other lib for snapshots and in this case if I made 2 or more snapshots, without any name/postfix, then it automaticaly created "counters". in this case first snapshot filename was something like "add new todo#0.png" and second "add new todo#1.png" and so one, the number afrer # was increasing for every next snapshot filename in test. But in this lib if I use 10 times in one test cy.matchImageSnapshot(); each snapshot filename will be exactly the same, so each cy.matchImageSnapshot(); will override snapshot made before
You can pass an argument to cy.matchImageSnapshot() yourself to get round this. This is advisible to make it clear what your snapshots are actually for
it.only('add new todo', () => {
cy.matchImageSnapshot('no todo items added'); <-------------------------- First snapshot
cy.get('[data-test=new-todo]').type(`test{enter}`)
cy.matchImageSnapshot('added one todo item'); <-------------------------- Second snapshot
})
Yes, I know but it will be nice if I don't pass anything, then will be counter which will be increace automatically
I think it makes sense here to explicity name your snapshots so that when browsing them in pull requests or the cypress directory they make sense to other developers
Names like add new todo 1 and add new todo 2 are not useful. I'd recommend picking meaningful names for your snapshots
However I'm open to adding this feature if you'd like to contribute a pull request