Exemplo n.º 1
0
func (s *errStore) prependErr(prefix string) {
	if s.err != nil {
		var msg = fmt.Sprintf("%s: %s", prefix, s.err.Error())
		switch {
		case store.IsPathNotFoundError(s.err):
			s.err = store.NewPathNotFoundError(msg)
		case store.IsAccessDeniedError(s.err):
			s.err = store.NewAccessDeniedError(msg)
		default:
			s.err = fmt.Errorf(msg)
		}
	}
}
Exemplo n.º 2
0
// https://github.com/fxnn/gone/issues/7 No.2 negative execute
func TestCreateFileDeniesWhenWorldExecutePermissionIsMissing(t *testing.T) {
	skipOnWindows(t)

	tmpdir := createTempDirInCurrentwd(t, 0772) // World write flag
	defer removeTempDirFromCurrentwd(t, tmpdir)

	sut := sutNotAuthenticated(t)

	writeCloser := sut.OpenWriter(requestGET("/" + tmpdir + "/newFile"))
	closed(writeCloser)
	if err := sut.Err(); err == nil || !store.IsAccessDeniedError(err) {
		t.Fatalf("expected AccessDeniedError on %s, but got %s", tmpdir+"/newFile", err)
	}
}
Exemplo n.º 3
0
// https://github.com/fxnn/gone/issues/7 No.3 negative (execute)
func TestReadExistingFileInsideDirectoryDeniesOnMissingExecutePermission(t *testing.T) {
	skipOnWindows(t)

	tmpdir := createTempWdInCurrentwd(t, 0770) // missing world execute flag
	defer removeTempWdFromCurrentwd(t, tmpdir)

	tmpfile := createTempFileInCurrentwd(t, 0774) // world read flag
	defer removeTempFileFromCurrentwd(t, tmpfile)

	sut := sutNotAuthenticated(t)

	readCloser := sut.OpenReader(requestGET("/" + tmpfile))
	closed(readCloser)
	if err := sut.Err(); err == nil || !store.IsAccessDeniedError(err) {
		t.Fatalf("expected AccessDeniedError on %s, but got %s", tmpfile, err)
	}
}