Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lakectl to present error while writing to protected branch #8454

Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e7fb7b8
Revert "docs: clarify auditing availble on enterprise (#8289)"
ItamarYuran Oct 23, 2024
cd5b80d
Merge branch 'master' of github.com:treeverse/lakeFS
ItamarYuran Jan 2, 2025
33ca670
got a decent error
ItamarYuran Jan 2, 2025
3c5addd
works
ItamarYuran Jan 5, 2025
5ed4479
without bs
ItamarYuran Jan 5, 2025
4aee694
changes, working
ItamarYuran Jan 6, 2025
cce44f3
lets see if something breaks
ItamarYuran Jan 7, 2025
36d9215
testing the tests
ItamarYuran Jan 8, 2025
03ad317
testing the tests#2
ItamarYuran Jan 8, 2025
22bd27e
testing the tests#2
ItamarYuran Jan 8, 2025
ca686ce
testing the tests#2
ItamarYuran Jan 8, 2025
c32d126
test test tests
ItamarYuran Jan 8, 2025
c7e1ca7
test test tests
ItamarYuran Jan 8, 2025
5495d4e
test test tests
ItamarYuran Jan 8, 2025
c1af8bb
test test tests
ItamarYuran Jan 8, 2025
700035a
test test tests
ItamarYuran Jan 8, 2025
ce1031e
test test tests
ItamarYuran Jan 8, 2025
e086c14
test test tests
ItamarYuran Jan 8, 2025
45f611d
test test tests
ItamarYuran Jan 8, 2025
36f38b5
test test tests
ItamarYuran Jan 8, 2025
c92bf21
test test tests
ItamarYuran Jan 8, 2025
fdeb73e
test test tests
ItamarYuran Jan 8, 2025
c8c3c6f
test test tests
ItamarYuran Jan 8, 2025
bdaa9a0
back to beginning
ItamarYuran Jan 8, 2025
57c109c
back to beginning
ItamarYuran Jan 8, 2025
f46df48
looks fresh
ItamarYuran Jan 8, 2025
58ef767
yalla
ItamarYuran Jan 12, 2025
40a6ba2
testing list
ItamarYuran Jan 12, 2025
72d105e
testing list
ItamarYuran Jan 12, 2025
230aff5
testing list
ItamarYuran Jan 12, 2025
291c181
***
ItamarYuran Jan 12, 2025
524a000
fs upload test
ItamarYuran Jan 12, 2025
3923c45
fs upload test
ItamarYuran Jan 12, 2025
edd352d
fs upload test
ItamarYuran Jan 12, 2025
c6c2c9a
with extre checks
ItamarYuran Jan 12, 2025
c3b9fca
with extre checks
ItamarYuran Jan 12, 2025
2743e1b
with extre checks
ItamarYuran Jan 12, 2025
b64a79e
switched tests location
ItamarYuran Jan 12, 2025
7004bff
switched tests location
ItamarYuran Jan 12, 2025
c5b6599
reduced
ItamarYuran Jan 13, 2025
99b25bc
works
ItamarYuran Jan 13, 2025
a62d71a
extended tests
ItamarYuran Jan 13, 2025
b7cd2d9
hopefuly now
ItamarYuran Jan 13, 2025
b33d289
weirrrd
ItamarYuran Jan 13, 2025
3bfb306
maybe
ItamarYuran Jan 13, 2025
0d67997
lets seeee
ItamarYuran Jan 13, 2025
9d0d3c1
hi there yalla
ItamarYuran Jan 13, 2025
c7bb775
yalla
ItamarYuran Jan 13, 2025
eaaeb66
check if fs upload is the problem
ItamarYuran Jan 15, 2025
e953d8f
kadima
ItamarYuran Jan 15, 2025
bc06a23
changes
ItamarYuran Jan 15, 2025
267cfed
check upload before rm
ItamarYuran Jan 15, 2025
7e553d3
whats going on
ItamarYuran Jan 15, 2025
15212df
changed name
ItamarYuran Jan 15, 2025
3d27ed3
with sleeping
ItamarYuran Jan 15, 2025
b07c7bc
with sleeping
ItamarYuran Jan 15, 2025
7e839e5
yallla
ItamarYuran Jan 15, 2025
1f52a58
yallla
ItamarYuran Jan 15, 2025
1b64392
yallla
ItamarYuran Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions esti/lakectl_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,39 @@ func TestLakectlLocal_pull(t *testing.T) {
}
}

func TestLakectlLocal_commitProtetedBranch(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Can you please also add a new test for deleting a file?

repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
tmpDir := t.TempDir()
fd, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)
require.NoError(t, fd.Close())
dataDir, err := os.MkdirTemp(tmpDir, "")
require.NoError(t, err)

vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
"REF": mainBranch,
"LOCAL_DIR": dataDir,
}
runCmd(t, Lakectl()+" repo create lakefs://"+vars["REPO"]+" "+vars["STORAGE"], false, false, vars)

runCmd(t, Lakectl()+" branch-protect add lakefs://"+vars["REPO"]+"/ '*'", false, false, vars)
// Cloning local dir
RunCmdAndVerifyContainsText(t, Lakectl()+" local clone lakefs://"+vars["REPO"]+"/"+vars["BRANCH"]+"/ "+vars["LOCAL_DIR"], false, "Successfully cloned lakefs://${REPO}/${REF}/ to ${LOCAL_DIR}.", vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "No diff found", vars)
// Adding file to local dir
fd, err = os.Create(filepath.Join(dataDir, "test.txt"))
require.NoError(t, err)
require.NoError(t, fd.Close())
RunCmdAndVerifyContainsText(t, Lakectl()+" local status "+vars["LOCAL_DIR"], false, "local ║ added ║ test.txt", vars)

// Try to commit local dir, expect failure
RunCmdAndVerifyFailureContainsText(t, Lakectl()+" local commit -m test "+vars["LOCAL_DIR"], false, "cannot write to protected branch", vars)
}

func TestLakectlLocal_commit(t *testing.T) {
tmpDir := t.TempDir()
fd, err := os.CreateTemp(tmpDir, "")
Expand Down
15 changes: 15 additions & 0 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,21 @@ func getStorageConfig(t *testing.T) *apigen.StorageConfig {
}
return storageResp.JSON200
}
func TestLakectlFsUpload_protectedBranch(t *testing.T) {
idanovo marked this conversation as resolved.
Show resolved Hide resolved
idanovo marked this conversation as resolved.
Show resolved Hide resolved
repoName := generateUniqueRepositoryName()
storage := generateUniqueStorageNamespace(repoName)
vars := map[string]string{
"REPO": repoName,
"STORAGE": storage,
"BRANCH": mainBranch,
}
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars)
runCmd(t, Lakectl()+" branch-protect add lakefs://"+repoName+"/ '*'", false, false, vars)
RunCmdAndVerifyContainsText(t, Lakectl()+" branch-protect list lakefs://"+repoName+"/ ", false, "*", vars)

vars["FILE_PATH"] = "data/ro/ro_1k.0"
RunCmdAndVerifyFailure(t, Lakectl()+" fs upload lakefs://"+repoName+"/"+mainBranch+"/"+vars["FILE_PATH"]+" -s files/ro_1k", false, "cannot write to protected branch\n403 Forbidden\n", vars)
}

func TestLakectlFsPresign(t *testing.T) {
config := getStorageConfig(t)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/helpers/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (u *presignUpload) uploadObject(ctx context.Context) (*apigen.ObjectStats,
if linkResp.JSON409 != nil {
return nil, ErrConflict
}
return nil, fmt.Errorf("link object to backing store: %w (%s)", ErrRequestFailed, linkResp.Status())
return nil, fmt.Errorf("link object to backing store: %w (%s)", ResponseAsError(linkResp), linkResp.Status())
}

func (u *presignUpload) Upload(ctx context.Context) (*apigen.ObjectStats, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/local/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (s *SyncManager) deleteRemote(ctx context.Context, remote *uri.URI, change
return
}
if resp.StatusCode() != http.StatusNoContent {
return fmt.Errorf("could not delete object: HTTP %d: %w", resp.StatusCode(), helpers.ErrRequestFailed)
return fmt.Errorf("could not delete object: HTTP %d: %w", resp.StatusCode(), helpers.ResponseAsError(resp))
}
return
}
Expand Down
Loading