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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
717d7b97
Commit
717d7b97
authored
Oct 26, 2016
by
James Lopez
Committed by
Robert Speicher
Nov 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes any symlinks before importing a project export file. Also added relevant spec.
parent
89a5afcf
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
4 deletions
+105
-4
lib/gitlab/import_export/file_importer.rb
lib/gitlab/import_export/file_importer.rb
+8
-0
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+8
-2
lib/gitlab/import_export/version_checker.rb
lib/gitlab/import_export/version_checker.rb
+8
-1
spec/lib/gitlab/import_export/file_importer_spec.rb
spec/lib/gitlab/import_export/file_importer_spec.rb
+42
-0
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+14
-0
spec/lib/gitlab/import_export/version_checker_spec.rb
spec/lib/gitlab/import_export/version_checker_spec.rb
+15
-1
spec/support/import_export/common_util.rb
spec/support/import_export/common_util.rb
+10
-0
No files found.
lib/gitlab/import_export/file_importer.rb
View file @
717d7b97
...
...
@@ -43,6 +43,14 @@ module Gitlab
raise
Projects
::
ImportService
::
Error
.
new
(
"Unable to decompress
#{
@archive_file
}
into
#{
@shared
.
export_path
}
"
)
unless
result
remove_symlinks!
end
def
remove_symlinks!
Dir
[
"
#{
@shared
.
export_path
}
/**/*"
].
each
do
|
path
|
FileUtils
.
rm
(
path
)
if
File
.
lstat
(
path
).
symlink?
end
true
end
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
717d7b97
...
...
@@ -9,8 +9,14 @@ module Gitlab
end
def
restore
begin
json
=
IO
.
read
(
@path
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
rescue
=>
e
Rails
.
logger
.
error
(
"Import/Export error:
#{
e
.
message
}
"
)
raise
Gitlab
::
ImportExport
::
Error
.
new
(
'Incorrect JSON format'
)
end
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
ActiveRecord
::
Base
.
no_touching
do
...
...
lib/gitlab/import_export/version_checker.rb
View file @
717d7b97
...
...
@@ -24,12 +24,19 @@ module Gitlab
end
def
verify_version!
(
version
)
if
Gem
::
Version
.
new
(
version
)
!=
Gem
::
Version
.
new
(
Gitlab
::
ImportExport
.
version
)
if
different_version?
(
version
)
raise
Gitlab
::
ImportExport
::
Error
.
new
(
"Import version mismatch: Required
#{
Gitlab
::
ImportExport
.
version
}
but was
#{
version
}
"
)
else
true
end
end
def
different_version?
(
version
)
Gem
::
Version
.
new
(
version
)
!=
Gem
::
Version
.
new
(
Gitlab
::
ImportExport
.
version
)
rescue
=>
e
Rails
.
logger
.
error
(
"Import/Export error:
#{
e
.
message
}
"
)
raise
Gitlab
::
ImportExport
::
Error
.
new
(
'Incorrect VERSION format'
)
end
end
end
end
spec/lib/gitlab/import_export/file_importer_spec.rb
0 → 100644
View file @
717d7b97
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
FileImporter
,
lib:
true
do
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
'test'
)
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/file_importer_spec"
}
let
(
:valid_file
)
{
"
#{
shared
.
export_path
}
/valid.json"
}
let
(
:symlink_file
)
{
"
#{
shared
.
export_path
}
/invalid.json"
}
let
(
:subfolder_symlink_file
)
{
"
#{
shared
.
export_path
}
/subfolder/invalid.json"
}
before
do
stub_const
(
'Gitlab::ImportExport::FileImporter::MAX_RETRIES'
,
0
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
allow_any_instance_of
(
Gitlab
::
ImportExport
::
CommandLineUtil
).
to
receive
(
:untar_zxf
).
and_return
(
true
)
setup_files
described_class
.
import
(
archive_file:
''
,
shared:
shared
)
end
after
do
FileUtils
.
rm_rf
(
export_path
)
end
it
'removes symlinks in root folder'
do
expect
(
File
.
exist?
(
symlink_file
)).
to
be
false
end
it
'removes symlinks in subfolders'
do
expect
(
File
.
exist?
(
subfolder_symlink_file
)).
to
be
false
end
it
'does not remove a valid file'
do
expect
(
File
.
exist?
(
valid_file
)).
to
be
true
end
def
setup_files
FileUtils
.
mkdir_p
(
"
#{
shared
.
export_path
}
/subfolder/"
)
FileUtils
.
touch
(
valid_file
)
FileUtils
.
ln_s
(
valid_file
,
symlink_file
)
FileUtils
.
ln_s
(
valid_file
,
subfolder_symlink_file
)
end
end
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
717d7b97
require
'spec_helper'
include
ImportExport
::
CommonUtil
describe
Gitlab
::
ImportExport
::
ProjectTreeRestorer
,
services:
true
do
describe
'restore project tree'
do
...
...
@@ -175,6 +176,19 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect
(
MergeRequest
.
find_by_title
(
'MR2'
).
source_project_id
).
to
eq
(
-
1
)
end
end
context
'project.json file access check'
do
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
setup_symlink
(
tmpdir
,
'project.json'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_call_original
restored_project_json
expect
(
shared
.
errors
.
first
).
not_to
include
(
'test'
)
end
end
end
end
end
end
spec/lib/gitlab/import_export/version_checker_spec.rb
View file @
717d7b97
require
'spec_helper'
include
ImportExport
::
CommonUtil
describe
Gitlab
::
ImportExport
::
VersionChecker
,
services:
true
do
describe
'bundle a project Git repo'
do
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
''
)
}
describe
'bundle a project Git repo'
do
let
(
:version
)
{
Gitlab
::
ImportExport
.
version
}
before
do
...
...
@@ -27,4 +29,16 @@ describe Gitlab::ImportExport::VersionChecker, services: true do
end
end
end
describe
'version file access check'
do
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
setup_symlink
(
tmpdir
,
'VERSION'
)
described_class
.
check!
(
shared:
shared
)
expect
(
shared
.
errors
.
first
).
not_to
include
(
'test'
)
end
end
end
end
spec/support/import_export/common_util.rb
0 → 100644
View file @
717d7b97
module
ImportExport
module
CommonUtil
def
setup_symlink
(
tmpdir
,
symlink_name
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
tmpdir
)
File
.
open
(
"
#{
tmpdir
}
/test"
,
'w'
)
{
|
file
|
file
.
write
(
"test"
)
}
FileUtils
.
ln_s
(
"
#{
tmpdir
}
/test"
,
"
#{
tmpdir
}
/
#{
symlink_name
}
"
)
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