class OwaspZap::Auth

Attributes

base[RW]
ctx[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/owasp_zap/auth.rb, line 4
def initialize(params = {})
    import_context(params[:context_name]) if !params[:context_name].nil?
    @ctx = params[:context] || 1 #default context is the1
    @base = params[:base] || "http://127.0.0.1:8080/JSON"
end

Public Instance Methods

import_context(context) click to toggle source

params: args a hash with the following keys -> values url: url including http:// post_data: an already encoded string like “email%3Dfoo%2540example.org%26passwd%3Dfoobar” TODO: offer a way to encode it, giving a hash?

# File lib/owasp_zap/auth.rb, line 35
def import_context(context)
  set_query "{@base}/context/action/importContext/",postData: context
  contexts = RestClient::get "{@base}/context/view/contextList"
  puts contexts
end
set_logged_in_indicator(args) click to toggle source
# File lib/owasp_zap/auth.rb, line 49
def set_logged_in_indicator(args)
    set_query "#{@base}/auth/action/setLoggedInIndicator/",:postData=>args[:indicator]
end
set_logged_out_indicator(args) click to toggle source
# File lib/owasp_zap/auth.rb, line 53
def set_logged_out_indicator(args)
    set_query "#{@base}/auth/action/setLoggedOutIndicator/", :indicator=>args[:indicator]
end
set_login_url(args) click to toggle source
# File lib/owasp_zap/auth.rb, line 41
def set_login_url(args)
    set_query "#{@base}/auth/action/setLoginUrl/",:postData=>args[:post_data]
end
set_logout_url(args) click to toggle source
# File lib/owasp_zap/auth.rb, line 45
def set_logout_url(args)
    set_query "#{@base}/auth/action/setLogoutUrl/",:postData=>args[:post_data]
end

Private Instance Methods

set_query(addr, params) click to toggle source

addr a string like #{@base}/auth/foo/bar params a hash with custom params that should be added to the query_values

# File lib/owasp_zap/auth.rb, line 61
def set_query(addr, params)
    default_params = {:zapapiformat=>"JSON",:url=>args[:url],:contextId=>@ctx}
    url Addressable::URI.parse addr
    url.query_values = default_params.merge(params)
    RestClient::get url.normalize.to_str
end
to_method(str) click to toggle source
# File lib/owasp_zap/auth.rb, line 73
def to_method(str)
    method_str = str.to_s
    method_str.extend OwaspZap::StringExtension # monkey patch just this instance
    method_str.snake_case
end
to_url(str) click to toggle source
# File lib/owasp_zap/auth.rb, line 67
def to_url(str)
    method_str = str.to_s
    method_str.extend OwaspZap::StringExtension # monkey patch just this instance
    method_str.camel_case
 end