-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7622 from hxtk/master
Fix for incorrect evaluation of error condition within libpod.LabelVolumePath.
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package libpod | ||
|
||
import ( | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLabelVolumePath(t *testing.T) { | ||
// Set up mocked SELinux functions for testing. | ||
oldRelabel := lvpRelabel | ||
oldInitLabels := lvpInitLabels | ||
oldReleaseLabel := lvpReleaseLabel | ||
defer func() { | ||
lvpRelabel = oldRelabel | ||
lvpInitLabels = oldInitLabels | ||
lvpReleaseLabel = oldReleaseLabel | ||
}() | ||
|
||
// Relabel returns ENOTSUP unconditionally. | ||
lvpRelabel = func(path string, fileLabel string, shared bool) error { | ||
return syscall.ENOTSUP | ||
} | ||
|
||
// InitLabels and ReleaseLabel both return dummy values and nil errors. | ||
lvpInitLabels = func(options []string) (string, string, error) { | ||
pLabel := "system_u:system_r:container_t:s0:c1,c2" | ||
mLabel := "system_u:object_r:container_file_t:s0:c1,c2" | ||
return pLabel, mLabel, nil | ||
} | ||
lvpReleaseLabel = func(label string) error { | ||
return nil | ||
} | ||
|
||
// LabelVolumePath should not return an error if the operation is unsupported. | ||
err := LabelVolumePath("/foo/bar") | ||
assert.NoError(t, err) | ||
} |