From 50a344ad871a8c75107ab48fc9282a2b286a65db Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Thu, 21 Jun 2018 17:20:37 +0200 Subject: [PATCH] update authorizer service - read from files, return beamline --- .gitignore | 5 +- .../src/asapo_authorizer/server/authorize.go | 87 ++++++++++++++-- .../asapo_authorizer/server/authorize_test.go | 98 ++++++++++++++++++- .../src/asapo_authorizer/server/server.go | 8 ++ common/go/src/asapo_common/utils/helpers.go | 12 +++ receiver/src/request.cpp | 8 ++ receiver/src/request.h | 3 + receiver/src/request_handler_authorize.cpp | 11 ++- receiver/src/request_handler_authorize.h | 1 + receiver/src/request_handler_file_write.cpp | 4 +- receiver/unittests/receiver_mocking.h | 2 + receiver/unittests/test_request.cpp | 14 +++ .../test_request_handler_authorizer.cpp | 6 +- .../test_request_handler_file_write.cpp | 9 +- tests/automatic/CMakeLists.txt | 1 + tests/automatic/authorizer/CMakeLists.txt | 2 + .../authorizer/check_authorize/CMakeLists.txt | 10 ++ .../check_authorize/OpenBeamTimes.txt | 22 +++++ .../authorizer/check_authorize/check_linux.sh | 18 ++++ .../check_authorize/check_windows.bat | 26 +++++ .../check_authorize/ip_bl_mapping/127.0.0.1 | 1 + .../check_authorize/settings.json.in | 8 ++ .../full_chain/simple_chain/check_linux.sh | 6 +- .../full_chain/simple_chain/check_windows.bat | 10 +- .../check_monitoring/check_linux.sh | 6 +- .../transfer_single_file/check_linux.sh | 6 +- .../transfer_single_file/check_windows.bat | 7 +- .../settings/authorizer_settings.json.tpl | 3 +- .../authorizer.json | 3 +- .../performance_full_chain_simple/test.sh | 5 +- .../authorizer.json | 3 +- .../performance_producer_receiver/test.sh | 5 +- 32 files changed, 377 insertions(+), 33 deletions(-) create mode 100644 tests/automatic/authorizer/CMakeLists.txt create mode 100644 tests/automatic/authorizer/check_authorize/CMakeLists.txt create mode 100644 tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt create mode 100644 tests/automatic/authorizer/check_authorize/check_linux.sh create mode 100644 tests/automatic/authorizer/check_authorize/check_windows.bat create mode 100644 tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1 create mode 100644 tests/automatic/authorizer/check_authorize/settings.json.in diff --git a/.gitignore b/.gitignore index 38f92c2ee..1dcbc1b24 100644 --- a/.gitignore +++ b/.gitignore @@ -122,4 +122,7 @@ doxygen #GO broker/pkg -discovery/pkg \ No newline at end of file +discovery/pkg +common/go/pkg +authorizer/pkg + diff --git a/authorizer/src/asapo_authorizer/server/authorize.go b/authorizer/src/asapo_authorizer/server/authorize.go index ad5cb4326..334cc21b1 100644 --- a/authorizer/src/asapo_authorizer/server/authorize.go +++ b/authorizer/src/asapo_authorizer/server/authorize.go @@ -3,6 +3,11 @@ package server import ( "net/http" "encoding/json" + "asapo_common/utils" + "path/filepath" + "strings" + log "asapo_common/logger" + "github.com/pkg/errors" ) type authorizationRequest struct { @@ -10,32 +15,98 @@ type authorizationRequest struct { OriginHost string } -func extractRequest(r *http.Request)(request authorizationRequest,err error) { +func extractRequest(r *http.Request) (request authorizationRequest, err error) { decoder := json.NewDecoder(r.Body) err = decoder.Decode(&request) return } -func authorize(request authorizationRequest) bool { - // todo: implement real check - if (request.BeamtimeId != "asapo_test") { +func splitHost(hostPort string) string { + s := strings.Split(hostPort, ":") + return s[0] +} + +func getBeamlineFromIP(ip string) (string, error) { + host := splitHost(ip) + lines, err := utils.ReadStringsFromFile(settings.IpBeamlineMappingFolder + string(filepath.Separator) + host) + if err != nil { + return "", err + } + + if len(lines) < 1 || len(lines[0]) == 0 { + return "", errors.New("file is empty") + } + + return lines[0], nil +} + +func checkBeamtimeExistsInStrings(info beamtimeInfo, lines []string) bool { + for _, line := range lines { + words := strings.Fields(line) + if len(words) < 3 { + continue + } + if words[1] == info.Beamline && words[2] == info.BeamtimeId { + return true + } + } + return false +} + +func beamtimeExists(info beamtimeInfo) bool { + lines, err := utils.ReadStringsFromFile(settings.BeamtimeBeamlineMappingFile) + + if err != nil || len(lines) < 3 { return false } + lines = lines[2:] + return checkBeamtimeExistsInStrings(info, lines) +} + +func authorize(request authorizationRequest) (bool, beamtimeInfo) { + for _, pair := range settings.AlwaysAllowedBeamtimes { + if pair.BeamtimeId == request.BeamtimeId { + return true, pair + } + } + var answer beamtimeInfo + + beamline, err := getBeamlineFromIP(request.OriginHost) + if err != nil { + log.Error("cannot find beamline for " + request.OriginHost + " - " + err.Error()) + return false, beamtimeInfo{} + } + + answer.Beamline = beamline + answer.BeamtimeId = request.BeamtimeId + if (!beamtimeExists(answer)) { + log.Error("cannot authorize beamtime " + answer.BeamtimeId + " for " + request.OriginHost + " in " + answer.Beamline) + return false, beamtimeInfo{} + } + log.Debug("authorized beamtime " + answer.BeamtimeId + " for " + request.OriginHost + " in " + answer.Beamline) + + return true, answer - return true } func routeAuthorize(w http.ResponseWriter, r *http.Request) { - request,err := extractRequest(r) + request, err := extractRequest(r) if err != nil { w.WriteHeader(http.StatusBadRequest) return } - if (!authorize(request)) { + ok, beamtimeInfo := authorize(request) + if (!ok) { w.WriteHeader(http.StatusUnauthorized) return } + res, err := utils.MapToJson(&beamtimeInfo) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + + } w.WriteHeader(http.StatusOK) - w.Write([]byte(request.BeamtimeId)) + w.Write([]byte(res)) } diff --git a/authorizer/src/asapo_authorizer/server/authorize_test.go b/authorizer/src/asapo_authorizer/server/authorize_test.go index 81e1df983..1c1b39b34 100644 --- a/authorizer/src/asapo_authorizer/server/authorize_test.go +++ b/authorizer/src/asapo_authorizer/server/authorize_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" "io/ioutil" + "os" ) type request struct { @@ -17,6 +18,11 @@ type request struct { message string } +func allowBeamlines(beamlines []beamtimeInfo) { + settings.AlwaysAllowedBeamtimes=beamlines +} + + func containsMatcher(substr string) func(str string) bool { return func(str string) bool { return strings.Contains(str, substr) } } @@ -35,12 +41,14 @@ func doAuthorizeRequest(path string,buf string) *httptest.ResponseRecorder { } func TestAuthorizeOK(t *testing.T) { + allowBeamlines([]beamtimeInfo{{"asapo_test","beamline"}}) request := makeRequest(authorizationRequest{"asapo_test","host"}) w := doAuthorizeRequest("/authorize",request) body, _ := ioutil.ReadAll(w.Body) - assert.Equal(t, string(body), "asapo_test", "") + assert.Contains(t, string(body), "asapo_test", "") + assert.Contains(t, string(body), "beamline", "") assert.Equal(t, http.StatusOK, w.Code, "") } @@ -62,5 +70,93 @@ func TestAuthorizeWrongPath(t *testing.T) { assert.Equal(t, http.StatusNotFound, w.Code, "") } +func TestAlwaysAuthorizeAllowed(t *testing.T) { + allowBeamlines([]beamtimeInfo{{"test","beamline"}}) + request := authorizationRequest{"asapo_test","host"} + ok,_ := authorize(request) + assert.Equal(t,false, ok, "") +} + +func TestSplitHost(t *testing.T) { + host := splitHost("127.0.0.1:112") + assert.Equal(t,"127.0.0.1", host, "") +} + + +func TestSplitHostNoPort(t *testing.T) { + host := splitHost("127.0.0.1") + assert.Equal(t,"127.0.0.1", host, "") +} + +func TestGetBeamlineFromIP(t *testing.T) { + beamline, err := getBeamlineFromIP("127.0.0.1:112") + assert.NotNil(t,err, "") + assert.Empty(t,beamline, "") + +} +func TestCheckBeamtimeExistsInStringsFalse(t *testing.T) { + beamInfo := beamtimeInfo{"123","bl"} + lines:=[]string{"111","flash pg2 11003932 beamtime start: 2018-06-11","petra3 p01 c20180508-000-COM20181 commissioning"} + ok := checkBeamtimeExistsInStrings(beamInfo,lines) + assert.False(t,ok, "") +} + + +func TestCheckBeamtimeExistsInStringsOk(t *testing.T) { + beamInfo := beamtimeInfo{"11003932","pg2"} + lines:=[]string{"111","flash pg2 11003932 beamtime start: 2018-06-11","petra3 p01 c20180508-000-COM20181 commissioning"} + ok := checkBeamtimeExistsInStrings(beamInfo,lines) + assert.True(t,ok, "") +} + +func TestAuthorizeWithFile(t *testing.T) { + settings.IpBeamlineMappingFolder="." + settings.BeamtimeBeamlineMappingFile="file.tmp" + + lines :=` +Open beam times as of Thursday, 2018/06/21 11:32 +Faclty BL BeamTime Id kind +flash bl1 11003924 beamtime start: 2018-04-24 +flash bl2 11003921 beamtime start: 2018-06-08 +flash fl24 11001734 beamtime start: 2018-06-13 +flash pg2 11003932 beamtime start: 2018-06-11 +flash thz 11005667 beamtime start: 2018-05-24 +petra3 ext 50000181 beamtime start: 2017-04-12 +petra3 ext 50000193 beamtime start: 2017-10-12 +petra3 ext 50000202 beamtime start: 2017-12-06 +petra3 ext 50000209 beamtime start: 2018-02-19 +petra3 ext 50000211 beamtime start: 2018-02-19 +petra3 ext 50000214 beamtime start: 2018-04-23 +petra3 ext 50000215 beamtime start: 2018-03-23 +petra3 ext 50000216 beamtime start: 2018-03-23 +petra3 ext 50000217 beamtime start: 2018-03-23 +petra3 ext 50000218 beamtime start: 2018-03-23 +petra3 ext 50000219 beamtime start: 2018-04-24 +petra3 ext 50000221 beamtime start: 2018-06-14 +petra3 p01 11004172 beamtime start: 2018-06-20 +petra3 p01 c20180508-000-COM20181 commissioning +petra3 p02.1 11004341 beamtime start: 2018-06-18 +` + + ioutil.WriteFile("file.tmp", []byte(lines), 0644) + ioutil.WriteFile("127.0.0.1", []byte("bl1"), 0644) + + + request := authorizationRequest{"11003924","127.0.0.1"} + w := doAuthorizeRequest("/authorize",makeRequest(request)) + + body, _ := ioutil.ReadAll(w.Body) + assert.Contains(t, string(body), request.BeamtimeId, "") + assert.Contains(t, string(body), "bl1", "") + assert.Equal(t, http.StatusOK, w.Code, "") + + request = authorizationRequest{"wrong","127.0.0.1"} + w = doAuthorizeRequest("/authorize",makeRequest(request)) + assert.Equal(t, http.StatusUnauthorized, w.Code, "") + + os.Remove("127.0.0.1") + os.Remove("file.tmp") + +} diff --git a/authorizer/src/asapo_authorizer/server/server.go b/authorizer/src/asapo_authorizer/server/server.go index 088339d07..4215eecec 100644 --- a/authorizer/src/asapo_authorizer/server/server.go +++ b/authorizer/src/asapo_authorizer/server/server.go @@ -1,9 +1,17 @@ package server +type beamtimeInfo struct { + BeamtimeId string + Beamline string +} + type serverSettings struct { Port int LogLevel string + IpBeamlineMappingFolder string + BeamtimeBeamlineMappingFile string + AlwaysAllowedBeamtimes []beamtimeInfo } var settings serverSettings diff --git a/common/go/src/asapo_common/utils/helpers.go b/common/go/src/asapo_common/utils/helpers.go index f1d0da4dc..9f02ac426 100644 --- a/common/go/src/asapo_common/utils/helpers.go +++ b/common/go/src/asapo_common/utils/helpers.go @@ -3,6 +3,7 @@ package utils import ( json "encoding/json" "io/ioutil" + "strings" ) func StringInSlice(a string, list []string) bool { @@ -36,3 +37,14 @@ func ReadJsonFromFile(fname string, config interface{}) error { return nil } + + +func ReadStringsFromFile(fname string) ([]string, error) { + content, err := ioutil.ReadFile(fname) + if err != nil { + return []string{},err + } + lines := strings.Split(string(content), "\n") + + return lines,nil +} \ No newline at end of file diff --git a/receiver/src/request.cpp b/receiver/src/request.cpp index d8ebd140a..8c10e991f 100644 --- a/receiver/src/request.cpp +++ b/receiver/src/request.cpp @@ -95,6 +95,14 @@ const char* Request::GetMessage() const { return request_header_.message; } +void Request::SetBeamline(std::string beamline) { + beamline_ = std::move(beamline); +} + +const std::string& Request::GetBeamline() const { + return beamline_; +} + std::unique_ptr<Request> RequestFactory::GenerateRequest(const GenericRequestHeader& request_header, SocketDescriptor socket_fd, std::string origin_uri, Error* err) const noexcept { diff --git a/receiver/src/request.h b/receiver/src/request.h index ecacb9bcd..b9350a9b6 100644 --- a/receiver/src/request.h +++ b/receiver/src/request.h @@ -35,6 +35,8 @@ class Request { const std::string& GetOriginUri() const; VIRTUAL const std::string& GetBeamtimeId() const; VIRTUAL void SetBeamtimeId(std::string beamtime_id); + VIRTUAL void SetBeamline(std::string beamline); + VIRTUAL const std::string& GetBeamline() const; std::unique_ptr<IO> io__; private: Error AllocateDataBuffer(); @@ -45,6 +47,7 @@ class Request { RequestHandlerList handlers_; std::string origin_uri_; std::string beamtime_id_; + std::string beamline_; }; class RequestFactory { diff --git a/receiver/src/request_handler_authorize.cpp b/receiver/src/request_handler_authorize.cpp index 7b2be86d3..597584601 100644 --- a/receiver/src/request_handler_authorize.cpp +++ b/receiver/src/request_handler_authorize.cpp @@ -3,6 +3,7 @@ #include "receiver_logger.h" #include "request.h" +#include "json_parser/json_parser.h" using std::chrono::high_resolution_clock; @@ -41,7 +42,14 @@ Error RequestHandlerAuthorize::Authorize(Request* request, const char* beamtime_ } last_updated_ = high_resolution_clock::now(); - beamtime_id_ = response; + + JsonStringParser parser{response}; + (err = parser.GetString("BeamtimeId", &beamtime_id_)) || + (err = parser.GetString("Beamline", &beamline_)); + if (err) { + return ErrorFromServerResponse(err, code); + } + return nullptr; } @@ -71,6 +79,7 @@ Error RequestHandlerAuthorize::ProcessOtherRequest(Request* request) const { } } request->SetBeamtimeId(beamtime_id_); + request->SetBeamline(beamline_); return nullptr; } diff --git a/receiver/src/request_handler_authorize.h b/receiver/src/request_handler_authorize.h index ee21db880..59069240c 100644 --- a/receiver/src/request_handler_authorize.h +++ b/receiver/src/request_handler_authorize.h @@ -21,6 +21,7 @@ class RequestHandlerAuthorize final: public RequestHandler { std::unique_ptr<HttpClient>http_client__; private: mutable std::string beamtime_id_; + mutable std::string beamline_; mutable std::chrono::high_resolution_clock::time_point last_updated_; Error ProcessAuthorizationRequest(Request* request) const; Error ProcessOtherRequest(Request* request) const; diff --git a/receiver/src/request_handler_file_write.cpp b/receiver/src/request_handler_file_write.cpp index 1702fc161..552393f76 100644 --- a/receiver/src/request_handler_file_write.cpp +++ b/receiver/src/request_handler_file_write.cpp @@ -16,7 +16,9 @@ Error RequestHandlerFileWrite::ProcessRequest(Request* request) const { const FileData& data = request->GetData(); auto fname = request->GetFileName(); - auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator + request->GetBeamtimeId() + kPathSeparator; + auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator + + request->GetBeamline() + kPathSeparator + + request->GetBeamtimeId() + kPathSeparator; auto err = io__->WriteDataToFile(root_folder + fname, data, fsize); if (!err) { log__->Debug("saved file of size " + std::to_string(fsize) + " to " + root_folder + fname); diff --git a/receiver/unittests/receiver_mocking.h b/receiver/unittests/receiver_mocking.h index 6187243e8..6881a0b51 100644 --- a/receiver/unittests/receiver_mocking.h +++ b/receiver/unittests/receiver_mocking.h @@ -53,9 +53,11 @@ class MockRequest: public Request { MOCK_CONST_METHOD0(GetDataID, uint64_t()); MOCK_CONST_METHOD0(GetData, const asapo::FileData & ()); MOCK_CONST_METHOD0(GetBeamtimeId, const std::string & ()); + MOCK_CONST_METHOD0(GetBeamline, const std::string & ()); MOCK_CONST_METHOD0(GetOpCode, asapo::Opcode ()); MOCK_CONST_METHOD0(GetMessage, const char* ()); MOCK_METHOD1(SetBeamtimeId, void (std::string)); + MOCK_METHOD1(SetBeamline, void (std::string)); }; diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp index c6e84575d..429a5b8e5 100644 --- a/receiver/unittests/test_request.cpp +++ b/receiver/unittests/test_request.cpp @@ -217,5 +217,19 @@ TEST_F(RequestTests, GetFileName) { ASSERT_THAT(fname, Eq(s)); } +TEST_F(RequestTests, SetGetBeamtimeId) { + request->SetBeamtimeId("beamtime"); + + ASSERT_THAT(request->GetBeamtimeId(), "beamtime"); +} + + +TEST_F(RequestTests, SetGetBeamline) { + request->SetBeamline("beamline"); + + ASSERT_THAT(request->GetBeamline(), "beamline"); +} + + } diff --git a/receiver/unittests/test_request_handler_authorizer.cpp b/receiver/unittests/test_request_handler_authorizer.cpp index 1b2d7b423..3fabc8000 100644 --- a/receiver/unittests/test_request_handler_authorizer.cpp +++ b/receiver/unittests/test_request_handler_authorizer.cpp @@ -15,7 +15,6 @@ #include "receiver_mocking.h" #include "../src/receiver_config.h" -#include "mock_receiver_config.h" using ::testing::Test; @@ -65,6 +64,7 @@ class AuthorizerHandlerTests : public Test { NiceMock<asapo::MockLogger> mock_logger; std::string expected_beamtime_id = "beamtime_id"; + std::string expected_beamline = "beamline"; std::string expected_producer_uri = "producer_uri"; std::string expected_authorization_server = "authorizer_host"; std::string expect_request_string = std::string("{\"BeamtimeId\":\"") + expected_beamtime_id + "\",\"OriginHost\":\"" + @@ -101,7 +101,7 @@ class AuthorizerHandlerTests : public Test { WillOnce( DoAll(SetArgPointee<3>(nullptr), SetArgPointee<2>(code), - Return(expected_beamtime_id) + Return("{\"BeamtimeId\":\"" + expected_beamtime_id + "\",\"Beamline\":" + "\"" + expected_beamline + "\"}") )); if (code != HttpCode::OK) { EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("failure authorizing"), @@ -133,6 +133,7 @@ class AuthorizerHandlerTests : public Test { ; if (!error && code == HttpCode::OK) { EXPECT_CALL(*mock_request, SetBeamtimeId(expected_beamtime_id)); + EXPECT_CALL(*mock_request, SetBeamline(expected_beamline)); } MockAuthRequest(error, code); @@ -225,6 +226,7 @@ TEST_F(AuthorizerHandlerTests, DataTransferRequestAuthorizeUsesCachedValue) { .WillOnce(Return(asapo::kOpcodeTransferData)); EXPECT_CALL(mock_http_client, Post_t(_, _, _, _)).Times(0); EXPECT_CALL(*mock_request, SetBeamtimeId(expected_beamtime_id)); + EXPECT_CALL(*mock_request, SetBeamline(expected_beamline)); auto err = handler.ProcessRequest(mock_request.get()); diff --git a/receiver/unittests/test_request_handler_file_write.cpp b/receiver/unittests/test_request_handler_file_write.cpp index 2ae3aedde..5a999e068 100644 --- a/receiver/unittests/test_request_handler_file_write.cpp +++ b/receiver/unittests/test_request_handler_file_write.cpp @@ -57,6 +57,7 @@ class FileWriteHandlerTests : public Test { NiceMock<asapo::MockLogger> mock_logger; std::string expected_file_name = "2.bin"; std::string expected_beamtime_id = "beamtime_id"; + std::string expected_beamline = "beamline"; uint64_t expected_file_size = 10; void MockRequestData(); void SetUp() override { @@ -112,6 +113,11 @@ void FileWriteHandlerTests::MockRequestData() { .WillOnce(ReturnRef(expected_beamtime_id)) ; + EXPECT_CALL(*mock_request, GetBeamline()) + .WillOnce(ReturnRef(expected_beamline)) + ; + + EXPECT_CALL(*mock_request, GetFileName()) .WillOnce(Return(expected_file_name)) ; @@ -125,7 +131,8 @@ TEST_F(FileWriteHandlerTests, CallsWriteFile) { MockRequestData(); - std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_beamtime_id + std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_beamline + + asapo::kPathSeparator + expected_beamtime_id + asapo::kPathSeparator + expected_file_name; EXPECT_CALL(mock_io, WriteDataToFile_t(expected_path.c_str(), _, expected_file_size)) diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt index bc93ec01b..8377afd4a 100644 --- a/tests/automatic/CMakeLists.txt +++ b/tests/automatic/CMakeLists.txt @@ -15,6 +15,7 @@ if(BUILD_BROKER) add_subdirectory(broker) endif() +add_subdirectory(authorizer) add_subdirectory(worker) diff --git a/tests/automatic/authorizer/CMakeLists.txt b/tests/automatic/authorizer/CMakeLists.txt new file mode 100644 index 000000000..db373a312 --- /dev/null +++ b/tests/automatic/authorizer/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(check_authorize) + diff --git a/tests/automatic/authorizer/check_authorize/CMakeLists.txt b/tests/automatic/authorizer/check_authorize/CMakeLists.txt new file mode 100644 index 000000000..4eeea1131 --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/CMakeLists.txt @@ -0,0 +1,10 @@ +set(TARGET_NAME asapo-authorizer) + +################################ +# Testing +################################ +file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OpenBeamTimes.txt BEAMTIMES_FILE ) +file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ip_bl_mapping BEAMLINES_FOLDER ) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/settings.json.in settings.json @ONLY) +add_script_test("${TARGET_NAME}-authorize" "$<TARGET_PROPERTY:${TARGET_NAME},EXENAME>" nomem + ) diff --git a/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt b/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt new file mode 100644 index 000000000..b218c3ec6 --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt @@ -0,0 +1,22 @@ +Open beam times as of Thursday, 2018/06/21 11:32 +Faclty BL BeamTime Id kind +flash bl1 11003924 beamtime start: 2018-04-24 +flash bl2 11003921 beamtime start: 2018-06-08 +flash fl24 11001734 beamtime start: 2018-06-13 +flash pg2 11003932 beamtime start: 2018-06-11 +flash thz 11005667 beamtime start: 2018-05-24 +petra3 ext 50000181 beamtime start: 2017-04-12 +petra3 ext 50000193 beamtime start: 2017-10-12 +petra3 ext 50000202 beamtime start: 2017-12-06 +petra3 ext 50000209 beamtime start: 2018-02-19 +petra3 ext 50000211 beamtime start: 2018-02-19 +petra3 ext 50000214 beamtime start: 2018-04-23 +petra3 ext 50000215 beamtime start: 2018-03-23 +petra3 ext 50000216 beamtime start: 2018-03-23 +petra3 ext 50000217 beamtime start: 2018-03-23 +petra3 ext 50000218 beamtime start: 2018-03-23 +petra3 ext 50000219 beamtime start: 2018-04-24 +petra3 ext 50000221 beamtime start: 2018-06-14 +petra3 p01 11004172 beamtime start: 2018-06-20 +petra3 p01 c20180508-000-COM20181 commissioning +petra3 p02.1 11004341 beamtime start: 2018-06-18 diff --git a/tests/automatic/authorizer/check_authorize/check_linux.sh b/tests/automatic/authorizer/check_authorize/check_linux.sh new file mode 100644 index 000000000..38c9bcf33 --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/check_linux.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +trap Cleanup EXIT + +Cleanup() { + echo cleanup + kill -9 $authorizeid +} + +$@ -config settings.json > authorizer.log & + +sleep 0.3 +authorizeid=`echo $!` + +curl -v --silent --data '{"BeamtimeId":"c20180508-000-COM20181","OriginHost":"127.0.0.1:5555"}' 127.0.0.1:5007/authorize --stderr - + diff --git a/tests/automatic/authorizer/check_authorize/check_windows.bat b/tests/automatic/authorizer/check_authorize/check_windows.bat new file mode 100644 index 000000000..443c05422 --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/check_windows.bat @@ -0,0 +1,26 @@ +SET database_name=data +SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" + +echo db.data.insert({"_id":1}) | %mongo_exe% %database_name% || goto :error +echo db.data.insert({"_id":2}) | %mongo_exe% %database_name% || goto :error + +set full_name="%1" +set short_name="%~nx1" + +start /B "" "%full_name%" -config settings.json + +ping 1.0.0.0 -n 1 -w 100 > nul + +C:\Curl\curl.exe -v --silent 127.0.0.1:5005/database/data/next --stderr - | findstr /c:\"_id\":1 || goto :error +C:\Curl\curl.exe -v --silent 127.0.0.1:5005/database/data/next --stderr - | findstr /c:\"_id\":2 || goto :error +C:\Curl\curl.exe -v --silent 127.0.0.1:5005/database/data/next --stderr - | findstr /c:"not found" || goto :error + +goto :clean + +:error +call :clean +exit /b 1 + +:clean +Taskkill /IM "%short_name%" /F +echo db.dropDatabase() | %mongo_exe% %database_name% diff --git a/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1 b/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1 new file mode 100644 index 000000000..9b9883faf --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1 @@ -0,0 +1 @@ +p01 diff --git a/tests/automatic/authorizer/check_authorize/settings.json.in b/tests/automatic/authorizer/check_authorize/settings.json.in new file mode 100644 index 000000000..0d8670b99 --- /dev/null +++ b/tests/automatic/authorizer/check_authorize/settings.json.in @@ -0,0 +1,8 @@ +{ + "Port": 5007, + "LogLevel":"debug", + "BeamtimeBeamlineMappingFile":"@BEAMTIMES_FILE@", + "IpBeamlineMappingFolder":"@BEAMLINES_FOLDER@" +} + + diff --git a/tests/automatic/full_chain/simple_chain/check_linux.sh b/tests/automatic/full_chain/simple_chain/check_linux.sh index ef79fadba..22b61d6e0 100644 --- a/tests/automatic/full_chain/simple_chain/check_linux.sh +++ b/tests/automatic/full_chain/simple_chain/check_linux.sh @@ -8,11 +8,13 @@ beamtime_id=asapo_test monitor_database_name=db_test proxy_address=127.0.0.1:8400 -receiver_folder=/tmp/asapo/receiver/files/${beamtime_id} +beamline=test +receiver_root_folder=/tmp/asapo/receiver/files +receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id} Cleanup() { echo cleanup - rm -rf ${receiver_folder} + rm -rf ${receiver_root_folder} nomad stop nginx nomad stop receiver nomad stop discovery diff --git a/tests/automatic/full_chain/simple_chain/check_windows.bat b/tests/automatic/full_chain/simple_chain/check_windows.bat index 35ecdb57d..8461997c0 100644 --- a/tests/automatic/full_chain/simple_chain/check_windows.bat +++ b/tests/automatic/full_chain/simple_chain/check_windows.bat @@ -1,6 +1,10 @@ SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" -SET beamtime_id=asapo_test -SET receiver_folder="c:\tmp\asapo\receiver\files\%beamtime_id%" +SET beamline=test +SET receiver_root_folder="c:\tmp\asapo\receiver\files" +SET receiver_folder="%receiver_root_folder%\%beamline%\%beamtime_id%" + + + set proxy_address="127.0.0.1:8400" echo db.%beamtime_id%.insert({dummy:1}) | %mongo_exe% %beamtime_id% @@ -34,7 +38,7 @@ c:\opt\consul\nomad stop discovery c:\opt\consul\nomad stop broker c:\opt\consul\nomad stop authorizer c:\opt\consul\nomad stop nginx -rmdir /S /Q %receiver_folder% +rmdir /S /Q %receiver_root_folder% echo db.dropDatabase() | %mongo_exe% %beamtime_id% diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh index 8a5a5e517..ff0af0589 100644 --- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh +++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh @@ -2,7 +2,9 @@ database_name=db_test beamtime_id=asapo_test -receiver_folder=/tmp/asapo/receiver/files/${beamtime_id} +beamline=test +receiver_root_folder=/tmp/asapo/receiver/files +receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id} set -e trap Cleanup EXIT @@ -15,7 +17,7 @@ Cleanup() { nomad stop authorizer nomad stop nginx echo "db.dropDatabase()" | mongo ${beamtime_id} - rm -rf ${receiver_folder} + rm -rf ${receiver_root_folder} } mkdir -p ${receiver_folder} diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh index a5e357400..972324483 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh +++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh @@ -6,11 +6,13 @@ trap Cleanup EXIT database_name=db_test beamtime_id=asapo_test -receiver_folder=/tmp/asapo/receiver/files/${beamtime_id} +beamline=test +receiver_root_folder=/tmp/asapo/receiver/files +receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id} Cleanup() { echo cleanup - rm -rf ${receiver_folder} + rm -rf ${receiver_root_folder} nomad stop receiver nomad stop discovery nomad stop authorizer diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat index 64c39dcc9..ea1dff5cd 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat +++ b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat @@ -1,6 +1,9 @@ SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" SET beamtime_id=asapo_test -SET receiver_folder="c:\tmp\asapo\receiver\files\%beamtime_id%" +SET beamline=test +SET receiver_root_folder="c:\tmp\asapo\receiver\files" +SET receiver_folder="%receiver_root_folder%\%beamline%\%beamtime_id%" + echo db.%beamtime_id%.insert({dummy:1})" | %mongo_exe% %beamtime_id% @@ -34,7 +37,7 @@ c:\opt\consul\nomad stop receiver c:\opt\consul\nomad stop discovery c:\opt\consul\nomad stop nginx c:\opt\consul\nomad stop authorizer -rmdir /S /Q %receiver_folder% +rmdir /S /Q %receiver_root_folder% echo db.dropDatabase() | %mongo_exe% %beamtime_id% diff --git a/tests/automatic/settings/authorizer_settings.json.tpl b/tests/automatic/settings/authorizer_settings.json.tpl index a1b6b3103..052462d53 100644 --- a/tests/automatic/settings/authorizer_settings.json.tpl +++ b/tests/automatic/settings/authorizer_settings.json.tpl @@ -1,6 +1,7 @@ { "Port": {{ env "NOMAD_PORT_authorizer" }}, - "LogLevel":"debug" + "LogLevel":"debug", + "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}] } diff --git a/tests/manual/performance_full_chain_simple/authorizer.json b/tests/manual/performance_full_chain_simple/authorizer.json index 4018a0ba2..64db1880d 100644 --- a/tests/manual/performance_full_chain_simple/authorizer.json +++ b/tests/manual/performance_full_chain_simple/authorizer.json @@ -1,6 +1,7 @@ { "Port": 5007, - "LogLevel":"info" + "LogLevel":"info", + "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}] } diff --git a/tests/manual/performance_full_chain_simple/test.sh b/tests/manual/performance_full_chain_simple/test.sh index 8e546b723..78263578b 100755 --- a/tests/manual/performance_full_chain_simple/test.sh +++ b/tests/manual/performance_full_chain_simple/test.sh @@ -7,7 +7,7 @@ trap Cleanup EXIT #clean-up Cleanup() { set +e -ssh ${receiver_node} rm -f ${receiver_dir}/files/${beamtime_id}/* +ssh ${receiver_node} rm -f ${receiver_dir}/files/${beamline}/${beamtime_id}/* ssh ${receiver_node} killall receiver ssh ${receiver_node} killall asapo-discovery ssh ${receiver_node} killall asapo-authorizer @@ -16,6 +16,7 @@ ssh ${broker_node} docker rm -f -v mongo } beamtime_id=asapo_test +beamline=test #monitoring_setup @@ -38,7 +39,7 @@ echo filesize: ${file_size}K, filenum: $file_num receiver_node=max-wgs receiver_port=4201 receiver_dir=/gpfs/petra3/scratch/yakubov/receiver_tests -ssh ${receiver_node} mkdir -p ${receiver_dir}/files/${beamtime_id} +ssh ${receiver_node} mkdir -p ${receiver_dir}/files/${beamline}/${beamtime_id} scp ../../../cmake-build-release/receiver/receiver ${receiver_node}:${receiver_dir} cat receiver.json | jq "to_entries | diff --git a/tests/manual/performance_producer_receiver/authorizer.json b/tests/manual/performance_producer_receiver/authorizer.json index 4018a0ba2..64db1880d 100644 --- a/tests/manual/performance_producer_receiver/authorizer.json +++ b/tests/manual/performance_producer_receiver/authorizer.json @@ -1,6 +1,7 @@ { "Port": 5007, - "LogLevel":"info" + "LogLevel":"info", + "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}] } diff --git a/tests/manual/performance_producer_receiver/test.sh b/tests/manual/performance_producer_receiver/test.sh index f8b4a25f8..eef1d5dd4 100755 --- a/tests/manual/performance_producer_receiver/test.sh +++ b/tests/manual/performance_producer_receiver/test.sh @@ -6,7 +6,7 @@ trap Cleanup EXIT Cleanup() { set +e -ssh ${service_node} rm -f ${service_dir}/files/${beamtime_id}/* +ssh ${service_node} rm -f ${service_dir}/files/${beamline}/${beamtime_id}/* ssh ${service_node} killall receiver ssh ${service_node} killall asapo-discovery ssh ${service_node} killall asapo-authorizer @@ -23,6 +23,7 @@ service_ip=`resolveip -s ${service_node}` discovery_port=5006 receiver_port=4201 beamtime_id=asapo_test +beamline=test monitor_node=zitpcx27016 @@ -95,7 +96,7 @@ echo =================================================================== ssh ${worker_node} ${worker_dir}/dummy-data-producer ${service_ip}:8400 ${beamtime_id} ${size} 1000 8 0 100 if [ "$1" == "true" ] then - ssh ${service_node} rm -f ${service_dir}/files/${beamtime_id}/* + ssh ${service_node} rm -f ${service_dir}/files/${beamline}/${beamtime_id}/* fi ssh ${service_node} docker rm -f -v mongo done -- GitLab