Skip to content

Commit

Permalink
Merge pull request #16069 from eduardoj/fix/issue_15905
Browse files Browse the repository at this point in the history
Ensure right encoding before checking for blank
  • Loading branch information
eduardoj committed Apr 30, 2024
2 parents 820b577 + 68e79c6 commit 7fb243c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api/app/services/rpmlint_log_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call
time_start = Time.now.to_f
content = begin
# Retrieve the content of the 'rpmlint.log' file
Backend::Api::BuildResults::Binaries.rpmlint_log(project, package, repository, architecture)
Backend::Api::BuildResults::Binaries.rpmlint_log(project, package, repository, architecture)&.scrub
rescue Backend::NotFoundError => e
@rpmlint_log_file_found = false

Expand Down
50 changes: 33 additions & 17 deletions src/api/spec/services/rpmlint_log_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,54 @@
subject { described_class.new(parameters).call }

let(:parameters) { ActionController::Parameters.new(project: 'home:user1', package: 'package1', repository: 'repo1', architecture: 'arch1') }
let(:invalid_byte_sequence_in_utf8) { "this is an invalid byte sequence \xED" }

before do
Flipper.enable(:request_show_redesign)
allow(Backend::Api::BuildResults::Binaries).to receive(:rpmlint_log)
.with('home:user1', 'package1', 'repo1', 'arch1')
.and_raise(Backend::NotFoundError, 'rpmlint.log: No such file or directory')
end

describe '#call' do
context 'no rpmlint.log file available since error exceeds allowed badness level' do
context 'rpmlint.log file is available in the backend with an invalid byte sequence' do
before do
allow(Backend::Api::BuildResults::Binaries).to receive(:file)
.with('home:user1', 'repo1', 'arch1', 'package1', '_log')
.and_return(file_fixture('rpmlint_log_extractor_log').read)
allow(Backend::Api::BuildResults::Binaries).to receive(:rpmlint_log)
.with('home:user1', 'package1', 'repo1', 'arch1')
.and_return(invalid_byte_sequence_in_utf8)
end

it 'extracts the summary from the build log file' do
expect(subject).to eq(file_fixture('rpmlint_log_extractor_expected').read)
it 'returns the text with the invalid byte sequence corrected' do
expect(subject).to eq('this is an invalid byte sequence �')
end
end

context 'when the rpmlint log contains invalid byte sequences in UTF-8' do
let(:invalid_byte_sequence_in_utf8) { "this is an invalid byte sequence \xED" }

context 'no rpmlint.log file available in the backend' do
before do
allow(Backend::Api::BuildResults::Binaries).to receive(:file)
.with('home:user1', 'repo1', 'arch1', 'package1', '_log')
.and_return(invalid_byte_sequence_in_utf8)
allow(Backend::Api::BuildResults::Binaries).to receive(:rpmlint_log)
.with('home:user1', 'package1', 'repo1', 'arch1')
.and_raise(Backend::NotFoundError, 'rpmlint.log: No such file or directory')
end

it 'extracts the summary from the build log file' do
expect(subject).to eq('this is an invalid byte sequence �')
context 'no _log file available since error exceeds allowed badness level' do
before do
allow(Backend::Api::BuildResults::Binaries).to receive(:file)
.with('home:user1', 'repo1', 'arch1', 'package1', '_log')
.and_return(file_fixture('rpmlint_log_extractor_log').read)
end

it 'extracts the summary from the build log file' do
expect(subject).to eq(file_fixture('rpmlint_log_extractor_expected').read)
end
end

context 'when the _log file contains invalid byte sequences in UTF-8' do
before do
allow(Backend::Api::BuildResults::Binaries).to receive(:file)
.with('home:user1', 'repo1', 'arch1', 'package1', '_log')
.and_return(invalid_byte_sequence_in_utf8)
end

it 'extracts the summary from the build log file' do
expect(subject).to eq('this is an invalid byte sequence �')
end
end
end
end
Expand Down

0 comments on commit 7fb243c

Please sign in to comment.