Welcome to mirror list, hosted at ThFree Co, Russian Federation.

jail_linux_test.go « jail « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c439d53d0521508b23eaf9f6ee72a844c596923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package jail_test

import (
	"os"
	"path"
	"testing"

	"github.com/stretchr/testify/require"

	"gitlab.com/gitlab-org/gitlab-pages/internal/jail"
)

func TestJailCreateAndCleanSubPaths(t *testing.T) {
	jailPath := tmpJailPath()
	subPath := "/pages/sub/path"

	require.NoError(t, os.MkdirAll(jailPath+subPath, 0755))
	defer os.RemoveAll(jailPath)

	cage := jail.CreateTimestamped("gitlab-pages", 0755)

	// Bind mount shared folder
	cage.MkDir(subPath, 0755)
	cage.Bind(subPath, subPath)

	require.NoError(t, cage.Build())
	require.NoError(t, cage.Dispose())

	_, err := os.Stat(path.Join(jailPath, subPath))
	require.True(t, os.IsNotExist(err), "%s in jail was not removed", subPath)
	_, err = os.Stat(jailPath)
	require.NoError(t, err, "/ in jail (corresponding to external directory) was removed")
}