Compare commits
No commits in common. "dfe1bdfeb483a1169f3ea63707427d1547ee9f3d" and "2e0f11c79a10d1573e3d4e936befe881a515bd0c" have entirely different histories.
dfe1bdfeb4
...
2e0f11c79a
@ -1,4 +1,4 @@
|
|||||||
package configloader
|
package configLoader
|
||||||
|
|
||||||
type MDWebDavUploaderConfig struct {
|
type MDWebDavUploaderConfig struct {
|
||||||
InstanceLink string `json:"instance"`
|
InstanceLink string `json:"instance"`
|
||||||
@ -23,45 +23,61 @@ func getConfigFilepath() string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loads configuration from the configuration file (located using
|
||||||
|
// getConfigFilepath()).
|
||||||
|
func loadFromFile() MDWebDavUploaderConfig {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a uniform filepath for the cache for the list of
|
// Returns a uniform filepath for the cache for the list of
|
||||||
// available parsers.
|
// available parsers.
|
||||||
func getParserCacheFilepath() string {
|
func getParserCacheFilepath() string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads configuration from the configuration file (located using
|
|
||||||
// getConfigFilepath()).
|
|
||||||
func LoadFromFile() MDWebDavUploaderConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stores a parser list to a cache file (located via
|
// Stores a parser list to a cache file (located via
|
||||||
// getParserCacheFilepath()).
|
// getParserCacheFilepath()).
|
||||||
func StoreParserList(parserList []ParserListItem) {
|
func storeParserList(parserList []ParserListItem) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of the available parsers.
|
// Returns a list of the available parsers.
|
||||||
func ListParsers() []ParserListItem {
|
func listParsers() []ParserListItem {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Checks if inputParser is in the list of available parsers.
|
// Checks if inputParser is in the list of available parsers.
|
||||||
// Returns the parser name or an error.
|
// Returns the parser name or an error.
|
||||||
func ValidateParser(inputParser string) (string, error) {
|
func validateParser(inputParser string) (string, error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if a directory is the entered directory can be used
|
||||||
|
// as an source directory for export data. As such, it does need
|
||||||
|
// to exist.
|
||||||
|
// Returns the directory name or an error.
|
||||||
|
func validateDir(dir string) (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates an input mail address.
|
// Validates an input mail address.
|
||||||
// Returns the valid mail address or an eQueries therror.
|
// Returns the valid mail address or an eQueries therror.
|
||||||
func ValidateMail(mail string) (string, error) {
|
func validateMail(mail string) (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates an entered instance URL.
|
// Validates an entered instance URL.
|
||||||
// Returns the entered URL in a unified form (minus optional
|
// Returns the entered URL in a unified form (minus optional
|
||||||
// trailing slashes and the /musdb suffix) or an error.
|
// trailing slashes and the /musdb suffix) or an error.
|
||||||
func ValidateInstanceLink(instanceUrl string) (string, error) {
|
func validateInstanceLink(instanceUrl string) (string, error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validates an institution ID.
|
||||||
|
// A valid institution ID returns a HTTP 200 response code when queried
|
||||||
|
// <instance_url> + "/institution/" + institution_id.
|
||||||
|
// Returns either the entered instance URL or an error.
|
||||||
|
func validateInstitutionId(institutionId int, instanceUrl string) (int, error) {
|
||||||
|
|
||||||
}
|
}
|
@ -1,32 +0,0 @@
|
|||||||
package configloader
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Validates an institution ID.
|
|
||||||
// A valid institution ID returns a HTTP 200 response code when queried
|
|
||||||
// <instance_url> + "/institution/" + institution_id.
|
|
||||||
// Returns either the entered instance URL or an error.
|
|
||||||
func ValidateInstitutionId(institutionId int, instanceUrl string) (int, error) {
|
|
||||||
|
|
||||||
if institutionId < 1 {
|
|
||||||
return 0, errors.New("Institution ID cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.Get(instanceUrl + "/institution/" + strconv.Itoa(institutionId))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return 0, errors.New("The institution page does not respond with HTTP 200, the institution does not seem to exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return institutionId, nil
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package configloader
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensures institution ID cannot be negative.
|
|
||||||
// does not exist.
|
|
||||||
func TestValidateInstitutionIdReturnsErrorOnNegativeInput(t *testing.T) {
|
|
||||||
|
|
||||||
_, err := ValidateInstitutionId(-1, "https://hessen.museum-digital.de")
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("ValidateInstitutionId() accepts should not accept negative IDs (test input: -1)")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensures non-existing IDs are rejected.
|
|
||||||
func TestValidateInstitutionIdReturnsErrorOnNonExistingId(t *testing.T) {
|
|
||||||
|
|
||||||
_, err := ValidateInstitutionId(300000, "https://hessen.museum-digital.de")
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("An institution 300000 should not exist in museum-digital:hessen (otherwise, adjust the test). A non-existing ID should be rejected.")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package configloader
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"io/fs"
|
|
||||||
"errors"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Checks if a directory is the entered
|
|
||||||
// directory can be used as an source directory
|
|
||||||
// for export data. As such, it does need to
|
|
||||||
// exist, and it needs to not contain unexpected files.
|
|
||||||
// Returns the directory name or an error.
|
|
||||||
func ValidateUploadDir(path string) (string, error) {
|
|
||||||
|
|
||||||
// Check the path actually exists
|
|
||||||
pathInfo, err := os.Stat(path)
|
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the input path is a directory
|
|
||||||
if !pathInfo.IsDir() {
|
|
||||||
return "", errors.New("The upload directory " + path + " is not a directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return absolute path
|
|
||||||
absPath, absPathErr := filepath.Abs(path)
|
|
||||||
if (absPathErr != nil) {
|
|
||||||
return "", errors.New("Invalid path")
|
|
||||||
}
|
|
||||||
return absPath, nil
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package configloader
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ValidateUploadDir() should return an error if the entered directory
|
|
||||||
// does not exist.
|
|
||||||
func TestValidateUploadDirFailsNonExistentDir(t *testing.T) {
|
|
||||||
|
|
||||||
returnVal, err := ValidateUploadDir("/this-directory-surely-does-not-exist")
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("ValidateUploadDir() accepts non-existent directory")
|
|
||||||
}
|
|
||||||
if returnVal != "" {
|
|
||||||
t.Fatalf("Return valid must be empty on failure")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test to ensure that an error is thrown if a file is entered, not a directory.
|
|
||||||
func TestValidateUploadDirFailsWithDirContainingUnexpectedFiles(t *testing.T) {
|
|
||||||
|
|
||||||
tmpDir := os.TempDir()
|
|
||||||
os.OpenFile(tmpDir + "/empty-file-for-testing-that-dirs-are-not-accepted.txt", os.O_RDONLY|os.O_CREATE, 0666)
|
|
||||||
|
|
||||||
returnVal, err := ValidateUploadDir(tmpDir + "/empty-file-for-testing-that-dirs-are-not-accepted.txt")
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("ValidateUploadDir() accepts fails as upload directory")
|
|
||||||
}
|
|
||||||
if returnVal != "" {
|
|
||||||
t.Fatalf("Return valid must be empty on failure")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidateUploadDirSucceedsWithValidDir(t *testing.T) {
|
|
||||||
|
|
||||||
tmpDir := os.TempDir()
|
|
||||||
testDir := filepath.Join(tmpDir, "/existing-dir-for-import")
|
|
||||||
mkdirErr := os.MkdirAll(testDir, os.ModePerm)
|
|
||||||
|
|
||||||
if mkdirErr != nil {
|
|
||||||
panic("Test failure: Failed to create test dir")
|
|
||||||
}
|
|
||||||
|
|
||||||
returnVal, err := ValidateUploadDir(tmpDir + "/existing-dir-for-import")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("ValidateUploadDir() fails with an existing, valid directory")
|
|
||||||
}
|
|
||||||
if returnVal == "" {
|
|
||||||
t.Fatalf("Return valid must be empty on failure")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package setup
|
package setup
|
||||||
|
|
||||||
import "gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
import "gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configLoader"
|
||||||
|
|
||||||
// Fetches user information from the relevant musdb API:
|
// Fetches user information from the relevant musdb API:
|
||||||
// https://demo.museum-digital.org/musdb/swagger/#/user/userReadOwnData
|
// https://demo.museum-digital.org/musdb/swagger/#/user/userReadOwnData
|
||||||
@ -21,7 +21,4 @@ func setup() error {
|
|||||||
|
|
||||||
validateInstanceLink()
|
validateInstanceLink()
|
||||||
|
|
||||||
// Get user name
|
|
||||||
// Get password
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package setup
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user