Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
054b6132
Commit
054b6132
authored
Nov 16, 2020
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Packages::Debian::FileEntry
parent
73368270
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
0 deletions
+142
-0
app/models/packages/debian/file_entry.rb
app/models/packages/debian/file_entry.rb
+44
-0
spec/models/packages/debian/file_entry_spec.rb
spec/models/packages/debian/file_entry_spec.rb
+98
-0
No files found.
app/models/packages/debian/file_entry.rb
0 → 100644
View file @
054b6132
# frozen_string_literal: true
module
Packages
module
Debian
class
FileEntry
include
ActiveModel
::
Model
DIGESTS
=
%i[md5 sha1 sha256]
.
freeze
FILENAME_REGEX
=
%r{
\A
[a-zA-Z0-9][a-zA-Z0-9_.~+-]*
\z
}
.
freeze
attr_accessor
:filename
,
:size
,
:md5sum
,
:section
,
:priority
,
:sha1sum
,
:sha256sum
,
:package_file
validates
:filename
,
:size
,
:md5sum
,
:section
,
:priority
,
:sha1sum
,
:sha256sum
,
:package_file
,
presence:
true
validates
:filename
,
format:
{
with:
FILENAME_REGEX
}
validate
:valid_package_file_digests
,
if:
->
{
md5sum
.
present?
&&
sha1sum
.
present?
&&
sha256sum
.
present?
&&
package_file
.
present?
}
def
component
return
'main'
if
section
.
blank?
return
'main'
unless
section
.
include?
(
'/'
)
section
.
split
(
'/'
)[
0
]
end
private
def
valid_package_file_digests
DIGESTS
.
each
do
|
digest
|
package_file_digest
=
package_file
[
"file_
#{
digest
}
"
]
sum
=
public_send
(
"
#{
digest
}
sum"
)
# rubocop:disable GitlabSecurity/PublicSend
next
if
package_file_digest
==
sum
errors
.
add
(
"
#{
digest
}
sum"
.
to_sym
,
"mismatch for
#{
filename
}
:
#{
package_file_digest
}
!=
#{
sum
}
"
)
end
end
end
end
end
spec/models/packages/debian/file_entry_spec.rb
0 → 100644
View file @
054b6132
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Debian
::
FileEntry
,
type: :model
do
let_it_be
(
:package_file
)
{
create
(
:debian_package_file
,
:dsc
)
}
let
(
:filename
)
{
'sample_1.2.3~alpha2.dsc'
}
let
(
:size
)
{
671
}
let
(
:md5sum
)
{
'3b0817804f669e16cdefac583ad88f0e'
}
let
(
:section
)
{
'libs'
}
let
(
:priority
)
{
'optional'
}
let
(
:sha1sum
)
{
'32ecbd674f0bfd310df68484d87752490685a8d6'
}
let
(
:sha256sum
)
{
'844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba'
}
let
(
:file_entry
)
do
described_class
.
new
(
filename:
filename
,
size:
size
,
md5sum:
md5sum
,
section:
section
,
priority:
priority
,
sha1sum:
sha1sum
,
sha256sum:
sha256sum
,
package_file:
package_file
)
end
subject
{
file_entry
}
describe
'validations'
do
it
{
is_expected
.
to
be_valid
}
describe
'#filename'
do
it
{
is_expected
.
to
validate_presence_of
(
:filename
)
}
it
{
is_expected
.
not_to
allow_value
(
'Hé'
).
for
(
:filename
)
}
end
describe
'#size'
do
it
{
is_expected
.
to
validate_presence_of
(
:size
)
}
end
describe
'#md5sum'
do
it
{
is_expected
.
to
validate_presence_of
(
:md5sum
)
}
it
{
is_expected
.
not_to
allow_value
(
'12345678901234567890123456789012'
).
for
(
:md5sum
).
with_message
(
'mismatch for sample_1.2.3~alpha2.dsc: 3b0817804f669e16cdefac583ad88f0e != 12345678901234567890123456789012'
)
}
end
describe
'#section'
do
it
{
is_expected
.
to
validate_presence_of
(
:section
)
}
end
describe
'#priority'
do
it
{
is_expected
.
to
validate_presence_of
(
:priority
)
}
end
describe
'#sha1sum'
do
it
{
is_expected
.
to
validate_presence_of
(
:sha1sum
)
}
it
{
is_expected
.
not_to
allow_value
(
'1234567890123456789012345678901234567890'
).
for
(
:sha1sum
).
with_message
(
'mismatch for sample_1.2.3~alpha2.dsc: 32ecbd674f0bfd310df68484d87752490685a8d6 != 1234567890123456789012345678901234567890'
)
}
end
describe
'#sha256sum'
do
it
{
is_expected
.
to
validate_presence_of
(
:sha256sum
)
}
it
{
is_expected
.
not_to
allow_value
(
'1234567890123456789012345678901234567890123456789012345678901234'
).
for
(
:sha256sum
).
with_message
(
'mismatch for sample_1.2.3~alpha2.dsc: 844f79825b7e8aaa191e514b58a81f9ac1e58e2180134b0c9512fa66d896d7ba != 1234567890123456789012345678901234567890123456789012345678901234'
)
}
end
describe
'#package_file'
do
it
{
is_expected
.
to
validate_presence_of
(
:package_file
)
}
end
end
describe
'#component'
do
subject
{
file_entry
.
component
}
context
'without section'
do
let
(
:section
)
{
nil
}
it
{
is_expected
.
to
eq
'main'
}
end
context
'with empty section'
do
let
(
:section
)
{
''
}
it
{
is_expected
.
to
eq
'main'
}
end
context
'with ruby section'
do
let
(
:section
)
{
'ruby'
}
it
{
is_expected
.
to
eq
'main'
}
end
context
'with contrib/ruby section'
do
let
(
:section
)
{
'contrib/ruby'
}
it
{
is_expected
.
to
eq
'contrib'
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment