Created
December 28, 2010 11:20
-
-
Save ripienaar/757144 to your computer and use it in GitHub Desktop.
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
# A mcollective security plugin that fails to decode messages randomly used to debug | |
# error propagation issues | |
module MCollective | |
module Security | |
class Randomfail < Base | |
require 'etc' | |
require 'yaml' | |
# Decodes a message by unserializing all the bits etc, it also validates | |
# it as valid using the psk etc | |
def decodemsg(msg) | |
body = YAML.load(msg.payload) | |
validrequest?(body) | |
body | |
end | |
# Encodes a reply | |
def encodereply(sender, target, msg, requestid, filter={}) | |
@log.debug("Encoded a message for request #{requestid}") | |
YAML.dump({:senderid => @config.identity, | |
:requestid => requestid, | |
:senderagent => sender, | |
:msgtarget => target, | |
:msgtime => Time.now.to_i, | |
:body => msg}) | |
end | |
# Encodes a request msg | |
def encoderequest(sender, target, msg, requestid, filter={}) | |
@log.debug("Encoding a request for '#{target}' with request id #{requestid}") | |
request = {:body => msg, | |
:senderid => @config.identity, | |
:requestid => requestid, | |
:msgtarget => target, | |
:filter => filter, | |
:msgtime => Time.now.to_i} | |
# if we're in use by a client add the callerid to the main client hashes | |
request[:callerid] = callerid if @initiated_by == :client | |
YAML.dump(request) | |
end | |
def validrequest?(req) | |
if @initiated_by == :client | |
if rand(10) % 2 == 0 | |
@stats.validated | |
return true | |
else | |
@stats.unvalidated | |
raise(SecurityValidationFailed, "Received an invalid signature in message") | |
end | |
else | |
return true | |
end | |
end | |
def callerid | |
"user=#{Etc.getlogin}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment