File indexing completed on 2024-05-05 05:29:37
0001 # SPDX-FileCopyrightText: 2017 Harald Sitter <sitter@kde.org> 0002 # 0003 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 require_relative 'test_helper' 0006 0007 require 'json' 0008 require 'webrick' 0009 0010 # monkey patch alias from put to get, upstream only aliases post -.- 0011 class WEBrick::HTTPServlet::ProcHandler 0012 alias do_PUT do_GET 0013 end 0014 0015 class TestDuplicateAttach < ATSPITest 0016 def setup 0017 server = WEBrick::HTTPServer.new(Port: 0) 0018 0019 port = server.config.fetch(:Port) 0020 ENV['DRKONQI_KDE_BUGZILLA_URL'] = "http://localhost:#{port}/" 0021 0022 @got_comment = false 0023 0024 server.mount_proc '/' do |req, res| 0025 query = req.request_uri.query 0026 0027 case req.request_method 0028 when 'GET' 0029 case req.path_info 0030 when '/rest/version' 0031 res.body = JSON.generate(version: '5.0.6') 0032 next 0033 when '/rest/product/ruby' # this is off because the product detection is a bit meh 0034 res.body = File.read("#{__dir__}/data/product.dolphin") 0035 next 0036 when '/rest/login' 0037 unless query.include?('login=xxx') && query.include?('password=yyy') 0038 abort 0039 end 0040 0041 res.body = JSON.generate(token: '123', id: '321') 0042 next 0043 when '/rest/bug', '/rest/bug/375161' 0044 res.body = File.read("#{__dir__}/data/bugs") 0045 next 0046 when '/rest/bug/375161/comment' 0047 res.body = File.read("#{__dir__}/data/comments") 0048 next 0049 end 0050 when 'PUT' 0051 case req.path_info 0052 when '/rest/bug/375161' 0053 input = JSON.parse(req.body) 0054 if input['cc']&.[]('add')&.include?('xxx') 0055 res.body = File.read("#{__dir__}/data/bugs") 0056 next 0057 end 0058 end 0059 when 'POST' 0060 case req.path_info 0061 when '/rest/bug/375161/attachment' 0062 input = JSON.parse(req.body) 0063 if input['comment']&.include?('yyyyyyyyy') 0064 res.body = JSON.generate(ids: [375161]) 0065 @got_comment = true 0066 next 0067 end 0068 end 0069 end 0070 0071 warn "!!!!!!!!" 0072 res.keep_alive = false 0073 abort "ERROR Unexpected request #{req}" 0074 end 0075 0076 Thread.report_on_exception = true 0077 @api_server_thread = Thread.start { server.start } 0078 @api_server_thread.report_on_exception=true 0079 0080 @tracee = fork { loop { sleep(999_999_999) } } 0081 0082 assert File.exist?(DRKONQI_PATH), "drkonqi not at #{DRKONQI_PATH}" 0083 @drkonqi_pid = spawn(DRKONQI_PATH, 0084 '--signal', '11', 0085 '--pid', @tracee.to_s, 0086 '--bugaddress', 'submit@bugs.kde.org', 0087 '--dialog') 0088 puts "pid: #{@drkonqi_pid}" 0089 end 0090 0091 def teardown 0092 Process.kill('KILL', @tracee) 0093 Process.waitpid2(@tracee) 0094 @api_server_thread.kill 0095 @api_server_thread.join 0096 end 0097 0098 def drkonqi_running? 0099 Process.waitpid(@drkonqi_pid, Process::WNOHANG).nil? 0100 end 0101 0102 # When evaluating duplicates 0103 def test_duplicate_attach 0104 drkonqi = nil 0105 0106 8.times do # be gracious for drkonqi to come up an atspi 0107 drkonqi = ATSPI.applications.find { |x| x.name == 'drkonqi' } 0108 break if drkonqi 0109 sleep 2 0110 end 0111 0112 refute_nil drkonqi, 'Could not find drkonqi on atspi api.' \ 0113 " It is running: #{drkonqi_running?}" 0114 0115 accessible = find_in(drkonqi.windows[-1], name: 'Report Bug') 0116 press(accessible) 0117 0118 find_in(drkonqi, name: 'Crash Reporting Assistant') do |window| 0119 accessible = find_in(window, name: 'Next') 0120 press(accessible) 0121 0122 accessible = find_in(window, name: 'Yes') 0123 toggle_on(accessible) 0124 0125 accessible = find_in(window, name: /^What I was doing when the application.+/) 0126 toggle_on(accessible) 0127 0128 accessible = find_in(window, name: 'Next') 0129 press(accessible) 0130 0131 loop do 0132 # Drkonqi is now doing the trace, wait until it is done. 0133 accessible = find_in(window, name: 'Next') 0134 refute_nil accessible 0135 if accessible.states.include?(:sensitive) 0136 press(accessible) 0137 break 0138 end 0139 warn accessible.states 0140 sleep 2 0141 end 0142 0143 # Set pseudo login data if there are none. 0144 accessible = find_in(window, name: 'Username input') 0145 accessible.text.set_to 'xxx' if accessible.text.length <= 0 0146 # the lineedit is in fact an element on the input. why wouldn't it be... 0147 accessible = find_in(window, name: 'Password input').children[0] 0148 accessible.text.set_to 'yyy' if accessible.text.length <= 0 0149 0150 accessible = find_in(window, name: 'Login') 0151 press(accessible) 0152 0153 sleep 2 # Wait for login and bug listing 0154 0155 accessible = find_in(window, name: '375161') 0156 toggle_on(accessible) 0157 0158 accessible = find_in(window, name: 'Open selected report') 0159 press(accessible) 0160 end 0161 0162 find_in(drkonqi, name: 'Bug Description') do |window| 0163 accessible = find_in(window, name: 'Suggest this crash is related') 0164 press(accessible) 0165 end 0166 0167 find_in(drkonqi, name: 'Related Bug Report') do |window| 0168 accessible = find_in(window, name: /^Completely sure: attach my information.+/) 0169 toggle_on(accessible) 0170 0171 accessible = find_in(window, name: 'Continue') 0172 press(accessible) 0173 end 0174 0175 find_in(drkonqi, name: 'Crash Reporting Assistant') do |window| 0176 accessible = find_in(window, name: /^The report is going to be attached.+/) 0177 refute_nil accessible 0178 0179 accessible = find_in(window, name: 'Next') 0180 press(accessible) 0181 0182 accessible = find_in(window, name: 'Information about the crash text') 0183 accessible.text.set_to(accessible.text.to_s + 0184 Array.new(128).collect { 'y' }.join) 0185 0186 accessible = find_in(window, name: 'Next') 0187 press(accessible) 0188 0189 accessible = find_in(window, name: 'Submit') 0190 press(accessible) 0191 0192 accessible = find_in(window, name: /.*Crash report sent.*/) 0193 refute_nil accessible 0194 0195 accessible = find_in(window, name: 'Finish') 0196 press(accessible) 0197 end 0198 0199 assert @got_comment # only true iff the server go tour yyyyyy garbage string 0200 end 0201 end