@ -1,9 +1,31 @@
# This test runs gitlab and checks if it works
# This test runs gitlab and performs the following tests:
# - Creating users
# - Pushing commits
# - over the API
# - over SSH
# - Creating Merge Requests and merging them
# - Opening and closing issues.
# - Downloading repository archives as tar.gz and tar.bz2
import ./make-test-python.nix ( { pkgs , lib , . . . }:
with lib ;
let
inherit ( import ./ssh-keys.nix pkgs ) snakeOilPrivateKey snakeOilPublicKey ;
initialRootPassword = " n o t p r o d u c t i o n " ;
in
import ./make-test-python.nix ( { pkgs , lib , . . . } : with lib ; {
rootProjectId = " 2 " ;
aliceUsername = " a l i c e " ;
aliceUserId = " 2 " ;
alicePassword = " a l i c e p a s s w o r d " ;
aliceProjectId = " 2 " ;
aliceProjectName = " t e s t - a l i c e " ;
bobUsername = " b o b " ;
bobUserId = " 3 " ;
bobPassword = " b o b p a s s w o r d " ;
bobProjectId = " 3 " ;
in {
name = " g i t l a b " ;
meta = with pkgs . lib . maintainers ; {
maintainers = [ globin yayayayaka ] ;
@ -31,6 +53,8 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; {
} ;
} ;
services . openssh . enable = true ;
services . dovecot2 = {
enable = true ;
enableImap = true ;
@ -77,8 +101,43 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; {
password = initialRootPassword ;
} ) ;
createProject = pkgs . writeText " c r e a t e - p r o j e c t . j s o n " ( builtins . toJSON {
name = " t e s t " ;
createUserAlice = pkgs . writeText " c r e a t e - u s e r - a l i c e . j s o n " ( builtins . toJSON rec {
username = aliceUsername ;
name = username ;
email = " a l i c e @ l o c a l h o s t " ;
password = alicePassword ;
skip_confirmation = true ;
} ) ;
createUserBob = pkgs . writeText " c r e a t e - u s e r - b o b . j s o n " ( builtins . toJSON rec {
username = bobUsername ;
name = username ;
email = " b o b @ l o c a l h o s t " ;
password = bobPassword ;
skip_confirmation = true ;
} ) ;
aliceAuth = pkgs . writeText " a l i c e - a u t h . j s o n " ( builtins . toJSON {
grant_type = " p a s s w o r d " ;
username = aliceUsername ;
password = alicePassword ;
} ) ;
bobAuth = pkgs . writeText " b o b - a u t h . j s o n " ( builtins . toJSON {
grant_type = " p a s s w o r d " ;
username = bobUsername ;
password = bobPassword ;
} ) ;
aliceAddSSHKey = pkgs . writeText " a l i c e - a d d - s s h - k e y . j s o n " ( builtins . toJSON {
id = aliceUserId ;
title = " s n a k e o i l @ n i x o s " ;
key = snakeOilPublicKey ;
} ) ;
createProjectAlice = pkgs . writeText " c r e a t e - p r o j e c t - a l i c e . j s o n " ( builtins . toJSON {
name = aliceProjectName ;
visibility = " p u b l i c " ;
} ) ;
putFile = pkgs . writeText " p u t - f i l e . j s o n " ( builtins . toJSON {
@ -89,6 +148,23 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; {
commit_message = " c r e a t e a n e w f i l e " ;
} ) ;
mergeRequest = pkgs . writeText " m e r g e - r e q u e s t . j s o n " ( builtins . toJSON {
id = bobProjectId ;
target_project_id = aliceProjectId ;
source_branch = " m a s t e r " ;
target_branch = " m a s t e r " ;
title = " A d d s o m e o t h e r f i l e " ;
} ) ;
newIssue = pkgs . writeText " n e w - i s s u e . j s o n " ( builtins . toJSON {
title = " u s e f u l i s s u e t i t l e " ;
} ) ;
closeIssue = pkgs . writeText " c l o s e - i s s u e . j s o n " ( builtins . toJSON {
issue_iid = 1 ;
state_event = " c l o s e " ;
} ) ;
# Wait for all GitLab services to be fully started.
waitForServices = ''
gitlab . wait_for_unit ( " g i t a l y . s e r v i c e " )
@ -105,6 +181,8 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; {
# The actual test of GitLab. Only push data to GitLab if
# `doSetup` is is true.
test = doSetup : ''
GIT_SSH_COMMAND = " s s h - o S t r i c t H o s t K e y C h e c k i n g = a c c e p t - n e w - o U s e r K n o w n H o s t s F i l e = / d e v / n u l l "
gitlab . succeed (
" c u r l - i s S f h t t p : / / g i t l a b | g r e p - i l o c a t i o n | g r e p h t t p : / / g i t l a b / u s e r s / s i g n _ i n "
)
@ -115,27 +193,222 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; {
" e c h o \" A u t h o r i z a t i o n : B e a r e r $ ( c u r l - X P O S T - H ' C o n t e n t - T y p e : a p p l i c a t i o n / j s o n ' - d @ ${ auth } h t t p : / / g i t l a b / o a u t h / t o k e n | ${ pkgs . jq } / b i n / j q - r ' . a c c e s s _ t o k e n ' ) \" > / t m p / h e a d e r s "
)
'' + o p t i o n a l S t r i n g d o S e t u p ''
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - X POST - H ' Content-Type : application/json ' - H @ /tmp/headers - d @ $ { createProject } http://gitlab/api/v4/projects ) " = " 201 " ] " " "
)
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - X POST - H ' Content-Type : application/json ' - H @ /tmp/headers - d @ $ { putFile } http://gitlab/api/v4/projects/2/repository/files/some-file.txt ) " = " 201 " ] " " "
)
with subtest ( " C r e a t e u s e r A l i c e " ) :
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - X POST - H ' Content-Type : application/json ' - H @ /tmp/headers - d @ $ { createUserAlice } http://gitlab/api/v4/users ) " = " 201 " ] " " "
)
gitlab . succeed (
" e c h o \" A u t h o r i z a t i o n : B e a r e r $ ( c u r l - X P O S T - H ' C o n t e n t - T y p e : a p p l i c a t i o n / j s o n ' - d @ ${ aliceAuth } h t t p : / / g i t l a b / o a u t h / t o k e n | ${ pkgs . jq } / b i n / j q - r ' . a c c e s s _ t o k e n ' ) \" > / t m p / h e a d e r s - a l i c e "
)
with subtest ( " C r e a t e u s e r B o b " ) :
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - X POST - H ' Content-Type : application/json ' - H @ /tmp/headers - d @ $ { createUserBob } http://gitlab/api/v4/users ) " = " 201 " ] " " "
)
gitlab . succeed (
" e c h o \" A u t h o r i z a t i o n : B e a r e r $ ( c u r l - X P O S T - H ' C o n t e n t - T y p e : a p p l i c a t i o n / j s o n ' - d @ ${ bobAuth } h t t p : / / g i t l a b / o a u t h / t o k e n | ${ pkgs . jq } / b i n / j q - r ' . a c c e s s _ t o k e n ' ) \" > / t m p / h e a d e r s - b o b "
)
with subtest ( " S e t u p G i t a n d S S H f o r A l i c e " ) :
gitlab . succeed ( " g i t c o n f i g - - g l o b a l u s e r . n a m e A l i c e " )
gitlab . succeed ( " g i t c o n f i g - - g l o b a l u s e r . e m a i l a l i c e @ n i x o s . i n v a l i d " )
gitlab . succeed ( " m k d i r - m 7 0 0 / r o o t / . s s h " )
gitlab . succeed ( " c a t ${ snakeOilPrivateKey } > / r o o t / . s s h / i d _ e c d s a " )
gitlab . succeed ( " c h m o d 6 0 0 / r o o t / . s s h / i d _ e c d s a " )
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-alice - d @ $ { aliceAddSSHKey } \
http://gitlab/api/v4/user/keys ) " = " 201 " ]
" " "
)
with subtest ( " C r e a t e a n e w r e p o s i t o r y " ) :
# Alice creates a new repository
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-alice \
- d @ $ { createProjectAlice } \
http://gitlab/api/v4/projects ) " = " 201 " ]
" " "
)
# Alice commits an initial commit
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-alice \
- d @ $ { putFile } \
http://gitlab/api/v4/projects/$ { aliceProjectId } /repository/files/some-file.txt ) " = " 201 " ] " " "
)
with subtest ( " g i t c l o n e o v e r H T T P " ) :
gitlab . succeed (
" " " g i t c l o n e h t t p : / / g i t l a b / a l i c e / ${ aliceProjectName } . g i t c l o n e - v i a - h t t p " " " ,
timeout = 15
)
with subtest ( " P u s h a c o m m i t v i a S S H " ) :
gitlab . succeed (
f " " " G I T _ S S H _ C O M M A N D = " { GIT_SSH_COMMAND } " g i t c l o n e g i t l a b @ g i t l a b : a l i c e / ${ aliceProjectName } . g i t " " " ,
timeout = 15
)
gitlab . succeed (
" " " e c h o " a commit sent over ssh " > ${ aliceProjectName } / s s h . t x t " " "
)
gitlab . succeed (
" " "
cd $ { aliceProjectName } || exit 1
git add .
" " "
)
gitlab . succeed (
" " "
cd $ { aliceProjectName } || exit 1
git commit - m " A d d a c o m m i t t o b e s e n t o v e r s s h "
" " "
)
gitlab . succeed (
f " " "
cd $ { aliceProjectName } || exit 1
GIT_SSH_COMMAND = " { G I T _ S S H _ C O M M A N D } " git push - - set-upstream origin master
" " " ,
timeout = 15
)
with subtest ( " F o r k a p r o j e c t " ) :
# Bob forks Alice's project
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-bob \
http://gitlab/api/v4/projects/$ { aliceProjectId } /fork ) " = " 201 " ]
" " "
)
# Bob creates a commit
gitlab . wait_until_succeeds (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-bob \
- d @ $ { putFile } \
http://gitlab/api/v4/projects/$ { bobProjectId } /repository/files/some-other-file.txt ) " = " 201 " ]
" " "
)
with subtest ( " C r e a t e a M e r g e R e q u e s t " ) :
# Bob opens a merge request against Alice's repository
gitlab . wait_until_succeeds (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-bob \
- d @ $ { mergeRequest } \
http://gitlab/api/v4/projects/$ { bobProjectId } /merge_requests ) " = " 201 " ]
" " "
)
# Alice merges the MR
gitlab . wait_until_succeeds (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X PUT \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-alice \
- d @ $ { mergeRequest } \
http://gitlab/api/v4/projects/$ { aliceProjectId } /merge_requests/1/merge ) " = " 200 " ]
" " "
)
with subtest ( " C r e a t e a n I s s u e " ) :
# Bob opens an issue on Alice's repository
gitlab . succeed (
" " " [ " $ ( curl \
- o /dev/null \
- w ' % { http_code } ' \
- X POST \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-bob \
- d @ $ { newIssue } \
http://gitlab/api/v4/projects/$ { aliceProjectId } /issues ) " = " 201 " ]
" " "
)
# Alice closes the issue
gitlab . wait_until_succeeds (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- X PUT \
- H ' Content-Type : application/json ' \
- H @ /tmp/headers-alice - d @ $ { closeIssue } http://gitlab/api/v4/projects/$ { aliceProjectId } /issues/1 ) " = " 200 " ]
" " "
)
'' + ''
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - H @ /tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.gz ) " = " 200 " ] " " "
)
gitlab . succeed (
" " " c u r l - H @ / t m p / h e a d e r s h t t p : / / g i t l a b / a p i / v 4 / p r o j e c t s / 2 / r e p o s i t o r y / a r c h i v e . t a r . g z > / t m p / a r c h i v e . t a r . g z " " "
)
gitlab . succeed (
" " " [ " $ ( curl - o /dev/null - w ' % { http_code } ' - H @ /tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.bz2 ) " = " 200 " ] " " "
)
gitlab . succeed (
" " " c u r l - o / d e v / n u l l - w ' % { h t t p _ c o d e } ' - H @ / t m p / h e a d e r s h t t p : / / g i t l a b / a p i / v 4 / p r o j e c t s / 2 / r e p o s i t o r y / a r c h i v e . t a r . b z 2 > / t m p / a r c h i v e . t a r . b z 2 " " "
)
gitlab . succeed ( " t e s t - s / t m p / a r c h i v e . t a r . g z " )
gitlab . succeed ( " t e s t - s / t m p / a r c h i v e . t a r . b z 2 " )
with subtest ( " D o w n l o a d a r c h i v e . t a r . g z " ) :
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- H @ /tmp/headers-alice \
http://gitlab/api/v4/projects/$ { aliceProjectId } /repository/archive.tar.gz ) " = " 200 " ]
" " "
)
gitlab . succeed (
" " "
curl \
- H @ /tmp/headers-alice \
http://gitlab/api/v4/projects/$ { aliceProjectId } /repository/archive.tar.gz > /tmp/archive.tar.gz
" " "
)
gitlab . succeed ( " t e s t - s / t m p / a r c h i v e . t a r . g z " )
with subtest ( " D o w n l o a d a r c h i v e . t a r . b z 2 " ) :
gitlab . succeed (
" " "
[ " $ ( c u r l \
- o /dev/null \
- w ' % { http_code } ' \
- H @ /tmp/headers-alice \
http://gitlab/api/v4/projects/$ { aliceProjectId } /repository/archive.tar.bz2 ) " = " 200 " ]
" " "
)
gitlab . succeed (
" " "
curl \
- H @ /tmp/headers-alice \
http://gitlab/api/v4/projects/$ { aliceProjectId } /repository/archive.tar.bz2 > /tmp/archive.tar.bz2
" " "
)
gitlab . succeed ( " t e s t - s / t m p / a r c h i v e . t a r . b z 2 " )
'' ;
in ''