Created
November 18, 2013 20:48
-
-
Save rjswenson/7535024 to your computer and use it in GitHub Desktop.
Jasmine Javascript testing for encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var encoder = { | |
setMessage: function() { | |
this.message = document.getElementById('message').value; | |
}, | |
getPassword: function() { | |
this.password = prompt("Enter your Decoder Password: "); | |
}, | |
setUrl: function() { | |
totalURL = document.URL + "?" + | |
encodeURI(this.encrypt()); | |
}, | |
replaceMessageWithUrl: function () { | |
replaceURL = totalURL.replace("encode.html", "decode.html"); | |
document.getElementById('message').value = replaceURL; | |
}, | |
encrypt: function() { | |
cypher = CryptoJS.AES.encrypt(this.message, this.password); | |
this.verify = CryptoJS.AES.decrypt(cypher, this.password).toString(CryptoJS.enc.Utf8); | |
return cypher | |
}, | |
protect: function() { | |
this.setMessage(); | |
this.getPassword(); | |
this.setUrl(); | |
this.replaceMessageWithUrl(); | |
} | |
} | |
document.getElementById('encrypt').onclick = function() { encoder.protect() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Encoder", function(){ | |
it("encodes a string into a link", function(){ | |
encoder.protect = function(){ | |
encoder.message = "A secret"; | |
encoder.password = "password"; | |
encoder.encrypt(); | |
}; | |
encoder.encrypt = function() { | |
cypher = CryptoJS.AES.encrypt(this.message, this.password); | |
this.verify = CryptoJS.AES.decrypt(cypher, this.password).toString(CryptoJS.enc.Utf8); | |
return cypher | |
}; | |
encoder.protect(); | |
expect(encoder.verify).toEqual("A secret"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment