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

Problem (bug?) with basic auth js script after upgrade from 0.9.6 to 1.0.0 #1531

Closed
intest opened this issue Mar 21, 2021 · 5 comments
Closed
Labels

Comments

@intest
Copy link

intest commented Mar 21, 2021

I've just upgraded Karate from 0.9.6 to 1.0.0 and I'm struggling with basic auth. Previously it worked perfect, now I'm getting this:

:karate-runner:test FAILED
nameOfTheRunner > [7.1:119] Scenario title FAILED    
org.opentest4j.AssertionFailedError at AssertionUtils.java:39

And these details in the report:

org.opentest4j.AssertionFailedError: >>>> js failed:
01: function fn(creds) {
02:     var temp = creds.username + ':' + creds.password;
03:     var Base64 = Java.type('java.util.Base64');
04:     var encoded = Base64.getEncoder().encodeToString(temp.bytes);
05:     return 'Basic ' + encoded;
06:   }
<<<<
org.graalvm.polyglot.PolyglotException
- java.util.Base64$Encoder.encode(Base64.java:261)
- java.util.Base64$Encoder.encodeToString(Base64.java:315)
- <js>.fn(Unnamed:4)
classpath:features/metadata/metadata-single-bat.feature:5
	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
	at org.junit.jupiter.api.Assertions.fail(Assertions.java:117)

Any ideas? Is it a bug in Karate or am I doing something wrong? (beside the upgrade I didn't change anything else)

@ptrthomas
Copy link
Member

@intest
Copy link
Author

intest commented Mar 21, 2021

I forgot to metion, that I tried it also and I got:

org.opentest4j.AssertionFailedError: >>>> js failed:
01: function fn(creds) {
02:     var temp = creds.username + ':' + creds.password;
03:     var Base64 = Java.type('java.util.Base64');
04:     var encoded = Base64.getEncoder().encodeToString(temp.getBytes());
05:     return 'Basic ' + encoded;
06: }
<<<<
org.graalvm.polyglot.PolyglotException: TypeError: temp.getBytes is not a function
- <js>.fn(Unnamed:4)

Also tried with var encoded = Base64.encoder.encodeToString(temp.getBytes()); and still the same.
I'm not into JS so much, so I really don't know how to fix it. I would be really grateful for help.

@ptrthomas
Copy link
Member

@intest sorry this worked for others so you are certainly missing something. please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

refer: #1373 (comment)

@joelpramos
Copy link
Contributor

To use the toBytes() the object needs to be a string. I think I stumbled on this Peter but forgot to report but it’s just this engine that’s “less forgiving”. @intest do temp.toString().getBytes()

@intest
Copy link
Author

intest commented Mar 21, 2021

It works! Thank you so much @joelpramos :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants