-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Timestamp Optional #735
Timestamp Optional #735
Conversation
Thanks a lot for your time and effort @jayharper 👍 In order to get your PR merged, please squash your commits like pointed out in our Guidelines on Submitting a Pull Request. |
My apologies for not squashing to a single commit originally. |
Looks good @jayharper ! 👍 from me @herom |
@@ -3,10 +3,11 @@ | |||
var crypto = require('crypto') | |||
, passwordDigest = require('../utils').passwordDigest; | |||
|
|||
function WSSecurity(username, password, passwordType) { | |||
function WSSecurity(username, password, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the passwordType
String param was not only replaced by an options
Object parameter, we should do something like this when setting this._passwordType
:
options = options || {};
this._passwordType = typeof options === 'string' ? options : options.passwordType;
this._hasTimeStamp = options.hasTimeStamp;
Also, I think we should update the README in order to let the people know, that an options
Object is expected and what it could contain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@herom take a look at my new updates. My goal was not to break implementations utilizing the passwordType
string parameter. The options
object is not required but rather optional. The passwordType
property default is PasswordText
and the hasTimeStamp
property will default to true.
I just addressed some concerns I had regarding the newly introduced |
this._passwordType = options; | ||
this._passwordType = this._passwordType === 'PasswordDigest' ? 'PasswordDigest' : 'PasswordText'; | ||
} else { | ||
this._passwordType = typeof options.passwordType !== 'undefined' ? options.passwordType : 'PasswordText'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for your patience @jayharper 👍
I think it's completely viable to set this._passwordType
and this._hasTimeStamp
properties once without setting them and resetting them within the next line. So if you please - as a last step - could change the "double set"-lines with "one-liners" like:
if (typeof options === 'string') {
this._passwordType = options ? options : 'PasswordText';
} else {
this._passwordType = options.passwordType ? options.passwordType : 'PasswordText';
}
this._hasTimeStamp = !!options.hasTimeStamp; // implicit Boolean conversion!
This would a) shorten the code and b) make it more readable. Thanks a lot for your understanding 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@herom I understand your desire to shorten the code and make it more readable, unfortunately your suggested code does not pass the original and the two new propogate basic security tests I have implemented. Could I ask you to check out my commit and run the tests yourself to help me find a solution?
Somehow I was not able to fork your repo and create a PR there, so here's the (working & tested) snippet for the "use strict";
var crypto = require('crypto');
var passwordDigest = require('../utils').passwordDigest;
var validPasswordTypes = ['PasswordDigest', 'PasswordText']; // <-- this is new!
function WSSecurity(username, password, options) {
options = options || {};
this._username = username;
this._password = password;
//must account for backward compatibility for passwordType String param as well as object options defaults: passwordType = 'PasswordText', hasTimeStamp = true
if (typeof options === 'string') {
this._passwordType = options ? options : 'PasswordText';
} else {
this._passwordType = options.passwordType ? options.passwordType : 'PasswordText';
}
if (validPasswordTypes.indexOf(this._passwordType) === -1) {
this._passwordType = 'PasswordText';
}
this._hasTimeStamp = options.hasTimeStamp || typeof options.hasTimeStamp === 'boolean' ? !!options.hasTimeStamp : true;
} |
Adding test for basic security no timestamp Adding test basic security backward compatible check Adding test for basic security invalid options Fixing WSSecurity() function checks for backward compatibility and default values
@herom thanks for cleaning this up 👍. I have incorporated your changes and we should now be good to go. |
Thanks a ton 👍 👯 |
👯 |
Timestamp Optional
Added the option to generate a timestamp when creating a soap client. Also added a new test in request response sample to test this option.