00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <basis/istring.h>
00021 #include <basis/mutex.h>
00022 #include <data_struct/static_memory_gremlin.h>
00023 #include <octopus/entity_defs.h>
00024 #include <octopus/infoton.h>
00025 #include <octopus/octopus.h>
00026 #include <octopus/tentacle.h>
00027 #include <opsystem/application_shell.h>
00028 #include <loggers/console_logger.h>
00029 #include <data_struct/static_memory_gremlin.h>
00030 #include <sockets/address.h>
00031 #include <tentacles/login_tentacle.h>
00032 #include <tentacles/simple_entity_registry.h>
00033
00035
00036 istring base_list[] = { "cli", "simp" };
00037
00038 SAFE_STATIC_CONST(string_array, simp_classifier, (2, base_list))
00039
00040 class simple_infoton : public infoton
00041 {
00042 public:
00043 istring futzle;
00044
00045 simple_infoton() : infoton(simp_classifier()) {}
00046
00047 virtual void pack(byte_array &packed_form) const {
00048 futzle.pack(packed_form);
00049 }
00050 virtual bool unpack(byte_array &packed_form) {
00051 if (!futzle.unpack(packed_form)) return false;
00052 return true;
00053 }
00054 virtual int packed_size() const { return futzle.length() + 1; }
00055 virtual clonable *clone() const { return new simple_infoton(*this); }
00056
00057 private:
00058 };
00059
00061
00062
00063
00064
00065 class simple_tentacle : public tentacle
00066 {
00067 public:
00068 simple_tentacle() : tentacle(simp_classifier(), true) {}
00069
00070 virtual outcome reconstitute(const string_array &classifier,
00071 byte_array &packed_form, infoton * &reformed) {
00072 reformed = NIL;
00073 if (classifier != simp_classifier()) return NO_HANDLER;
00074 reformed = new simple_infoton;
00075 if (!reformed->unpack(packed_form)) {
00076 WHACK(reformed);
00077 return GARBAGE;
00078 }
00079 return OKAY;
00080 }
00081
00082 virtual outcome consume(infoton &to_chow,
00083 const octopus_request_id &formal(item_id), byte_array &transformed) {
00084 transformed.reset();
00085 if (to_chow.classifier() != simp_classifier()) return NO_HANDLER;
00086
00087 return OKAY;
00088 }
00089
00090 virtual void expunge(const octopus_entity &formal(to_zap)) {}
00091 };
00092
00094
00095
00096
00097
00098
00099 class test_octopus_security : public application_shell
00100 {
00101 public:
00102 test_octopus_security() : application_shell(class_name()) {}
00103 IMPLEMENT_CLASS_NAME("test_octopus_security");
00104 virtual int execute();
00105 };
00106
00107 int test_octopus_security::execute()
00108 {
00109 octopus logos("local", 18 * MEGABYTE);
00110 simple_tentacle *tenty = new simple_tentacle;
00111 logos.add_tentacle(tenty);
00112 tenty = NIL;
00113
00114
00115 simple_entity_registry *guardian = new simple_entity_registry;
00116 logos.add_tentacle(new login_tentacle(*guardian), true);
00117
00118
00119 octopus_entity jimbo("localhost", portable::process_id(), 128, 982938);
00120 octopus_request_id req1(jimbo, 1);
00121
00122
00123 guardian->add_entity(jimbo, byte_array());
00124
00125
00126 simple_infoton testose;
00127 simple_infoton *testose_copy = new simple_infoton(testose);
00128
00129
00130 outcome ret = logos.evaluate(testose_copy, req1);
00131 if (ret != tentacle::OKAY)
00132 deadly_error(class_name(), "first test",
00133 istring("the operation failed with an error ")
00134 + tentacle::outcome_name(ret));
00135
00136
00137 octopus_entity burfo("localhost", portable::process_id(), 372, 2989);
00138 octopus_request_id req2(burfo, 1);
00139
00140
00141 testose_copy = new simple_infoton(testose);
00142 ret = logos.evaluate(testose_copy, req2);
00143 if (ret == tentacle::OKAY)
00144 deadly_error(class_name(), "second test",
00145 istring("the operation didn't fail when it should have."));
00146 else if (ret != tentacle::DISALLOWED)
00147 deadly_error(class_name(), "second test",
00148 istring("the operation didn't provide the proper outcome, it gave: ")
00149 + tentacle::outcome_name(ret));
00150
00151
00152 guardian->zap_entity(jimbo);
00153
00154
00155 testose_copy = new simple_infoton(testose);
00156 ret = logos.evaluate(testose_copy, req1);
00157 if (ret == tentacle::OKAY)
00158 deadly_error(class_name(), "third test",
00159 istring("the operation didn't fail when it should have."));
00160 else if (ret != tentacle::DISALLOWED)
00161 deadly_error(class_name(), "third test",
00162 istring("the operation didn't provide the proper outcome, it gave: ")
00163 + tentacle::outcome_name(ret));
00164
00165
00166 guardian->add_entity(burfo, byte_array());
00167
00168
00169 testose_copy = new simple_infoton(testose);
00170 ret = logos.evaluate(testose_copy, req2);
00171 if (ret != tentacle::OKAY)
00172 deadly_error(class_name(), "fourth test",
00173 istring("the operation failed with an error ")
00174 + tentacle::outcome_name(ret));
00175
00176 log("octopus:: security works for those functions tested.");
00177
00178 WHACK(guardian);
00179
00180 return 0;
00181 }
00182
00183 HOOPLE_MAIN(test_octopus_security, )
00184