Class: Continuum::LevelAccessPlatformReportingService

Inherits:
Object
  • Object
show all
Defined in:
src/lib/continuum/level_access_platform_reporting_service.rb

Overview

This class encapsulates all functionality for submitting assertions identified using Continuum to Level Access Platform.

Reporting test results from Continuum to Level Access Platform requires opening a scan session first by calling #open_scan_session, you will need to provide the workspace, digital property, scan tag, and session name that wil be used. Having the session created you can then send results to the Level Access Platform by calling #submit Don’t forget to close the scan session by calling #complete_scan_session.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, access_engine_version) ⇒ LevelAccessPlatformReportingService

Creates a new LevelAccessPlatformReportingService instance.

Parameters:

  • driver (Selenium::WebDriver::Driver)

    The selenium driver instance



70
71
72
73
74
75
76
77
78
79
80
81
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 70

def initialize(driver, access_engine_version)
    @driver = driver
    @access_engine_version = access_engine_version
    @api_key = Continuum.configuration.level_access_platform_configuration ? Continuum.configuration.level_access_platform_configuration.api_key : nil
    @org_instance_url = Continuum.configuration.level_access_platform_configuration ? Continuum.configuration.level_access_platform_configuration.org_instance_url : nil
    @workspace_id = nil
    @digital_property_id = nil
    @scan_tag_id = nil
    @session_name = nil
    @base_url = nil
    @active_scan_id = nil
end

Instance Attribute Details

#access_engine_versionString

Returns:

  • (String)


30
31
32
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 30

def access_engine_version
  @access_engine_version
end

#base_urlString? (readonly)

The base URL being used for the current scan session. This will be nil if the #open_scan_session function has not been called or if #complete_scan_session has been called without a subsequent call to #open_scan_session.

Returns:

  • (String, nil)

    The base URL being used for the current scan session.



65
66
67
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 65

def base_url
  @base_url
end

#digital_property_idString? (readonly)

The digital property id being used for the current scan session. This will be nil if the #open_scan_session function has not been called or if #complete_scan_session has been called without a subsequent call to #open_scan_session.

Returns:

  • (String, nil)

    The digital property id being used for the current scan session.



44
45
46
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 44

def digital_property_id
  @digital_property_id
end

#driverSelenium::WebDriver::Driver

Returns:

  • (Selenium::WebDriver::Driver)


27
28
29
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 27

def driver
  @driver
end

#scan_tag_idString? (readonly)

The scan tag id being used for the current scan session. This will be nil if the #open_scan_session function has not been called or if #complete_scan_session has been called without a subsequent call to #open_scan_session.

Returns:

  • (String, nil)

    The scan tag id being used for the current scan session.



51
52
53
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 51

def scan_tag_id
  @scan_tag_id
end

#session_nameString? (readonly)

The name of the current scan session. This will be nil if the #open_scan_session function has not been called or if #complete_scan_session has been called without a subsequent call to #open_scan_session.

Returns:

  • (String, nil)

    The name of the current scan session.



58
59
60
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 58

def session_name
  @session_name
end

#workspace_idString? (readonly)

The workspace id being used for the current scan session. This will be nil if the #open_scan_session function has not been called or if #complete_scan_session has been called without a subsequent call to #open_scan_session.

Returns:

  • (String, nil)

    The workspace id being used for the current scan session.



37
38
39
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 37

def workspace_id
  @workspace_id
end

Instance Method Details

#complete_scan_sessionObject

Completes the currently active scan session.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 186

def complete_scan_session()
    unless @active_scan_id
        raise Error.new('There is currently no active scan session. Please open a scan session and try again.')
    end

    body_params = {
        'complete' => true
    }
    NetworkUtil.post_to_level_access_platform("#{API_BASE_URL}/push/digital-properties/#{@digital_property_id}/scanSession/#{@active_scan_id}", body_params)

    @workspace_id = nil
    @digital_property_id = nil
    @scan_tag_id = nil
    @session_name = nil
    @base_url = nil
    @active_scan_id = nil
end

#open_scan_session(session_name, workspace_id = nil, digital_property_id = nil, scan_tag_id = nil, base_url = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 96

def open_scan_session(session_name, workspace_id = nil, digital_property_id = nil, scan_tag_id = nil, base_url = nil)
    if @active_scan_id
        raise Error.new('There is already an active scan session. Please complete it and retry.')
    end

    unless Continuum.configuration.level_access_platform_configuration
        raise Error.new('The levelAccessPlatform property must be present in the continuum.json configuration file')
    end
    unless @api_key
        raise Error.new('The levelAccessPlatform.apiKey property must be specified in the continuum.json configuration file')
    end
    unless @org_instance_url
        raise Error.new('The levelAccessPlatform.orgInstanceUrl property must be specified in the continuum.json configuration file')
    end

    unless workspace_id or Continuum.configuration.level_access_platform_configuration.workspace_id
        raise Error.new('A workspace id value must be provided either in the levelAccessPlatform.workspaceId property in the continuum.json configuration file or as an argument to this function')
    end
    unless digital_property_id or Continuum.configuration.level_access_platform_configuration.digital_property_id
        raise Error.new('A digital property id value must be provided either in the levelAccessPlatform.digitalPropertyId property in the continuum.json configuration file or as an argument to this function')
    end
    unless scan_tag_id or Continuum.configuration.level_access_platform_configuration.scan_tag_id
        raise Error.new('A scan tag id value must be provided either in the levelAccessPlatform.scanTagId property in the continuum.json configuration file or as an argument to this function')
    end

    body_params = {
        'workspaceId' => workspace_id ? workspace_id : Continuum.configuration.level_access_platform_configuration.workspace_id,
        'digitalPropertyId' => digital_property_id ? digital_property_id : Continuum.configuration.level_access_platform_configuration.digital_property_id,
        'scanTagId' => scan_tag_id ? scan_tag_id : Continuum.configuration.level_access_platform_configuration.scan_tag_id
    }
    response = NetworkUtil.post_to_level_access_platform("#{API_BASE_URL}/push/validate", body_params)
    unless response['valid']
        raise Error.new('Invalid Level Access Platform configuration')
    end

    @workspace_id = workspace_id ? workspace_id : Continuum.configuration.level_access_platform_configuration.workspace_id
    @digital_property_id = digital_property_id ? digital_property_id : Continuum.configuration.level_access_platform_configuration.digital_property_id
    @scan_tag_id = scan_tag_id ? scan_tag_id : Continuum.configuration.level_access_platform_configuration.scan_tag_id
    @session_name = session_name
    @base_url = base_url ? base_url : @driver.current_url

    body_params = {
        'baseUrl' => @base_url,
        'scanTagId' => @scan_tag_id,
        'source' => 'default',
        'scannerVersion' => {
            'access-engine' => @access_engine_version,
        },
        'sessionName' => @session_name,
        'viewport' => {
            'viewportType' => 'desktop',
            'width' => @driver.manage.window.size.width,
            'height' => @driver.manage.window.size.height
        }
    }
    response = NetworkUtil.post_to_level_access_platform("#{API_BASE_URL}/push/digital-properties/#{@digital_property_id}/scanSession", body_params)
    unless response.is_a?(String)
        raise Error.new("Invalid response recieved from Level Access Platform. Expected a string, but recieved: #{response}")
    end
    @active_scan_id = response
end

#submit(assertions) ⇒ Object

Submits the supplied list of assertions to Level Access Platform

Parameters:

  • assertions (Array<Assertion>)

    The list of assertions returned from Access Engine



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'src/lib/continuum/level_access_platform_reporting_service.rb', line 162

def submit(assertions)
    unless @active_scan_id
        raise Error.new('There is currently no active scan session. Please open a scan session and try again.')
    end

    results_data = [{
        'scanner' => 'access-engine',
        'version' => @access_engine_version,
        'payload': assertions
    }]
    results_json = results_data.to_json
    compressed_results = Zlib::gzip(results_json)
    encoded_results = Base64.strict_encode64(compressed_results)
    body_params = {
				'scanUrl' => @driver.current_url,
				'pageTitle' => @driver.title,
				'results' => encoded_results
    }
    NetworkUtil.post_to_level_access_platform("#{API_BASE_URL}/push/digital-properties/#{@digital_property_id}/scanSession/#{@active_scan_id}/scan-document?resultsCompression=gzip", body_params)
end