Skip to content

Commit

Permalink
Proxy::Write split up and tested
Browse files Browse the repository at this point in the history
trivially factored out WriteSysconfig, WriteCurlrc
  • Loading branch information
mvidner authored and mchf committed Jun 5, 2015
1 parent 13127c5 commit 60be5b2
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/modules/Proxy.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,16 @@ global define boolean Read() {
return true;
}

/**
* Write routing settings and apply changes
* @return true if success
*/
global define boolean Write() {

y2milestone("Writing configuration");
if(!modified) {
y2milestone("No changes to proxy configuration -> nothing to write");
return true;
}

list <string> steps = [
_("Update proxy configuration"),
];

string caption = _("Saving Proxy Configuration");
// sleep for longer time, so that progress does not disappear right afterwards
// but only when Progress is visible
integer sl = (Progress::status() == true ? 500 : 0);

Progress::New(caption, " ", size(steps), steps, [], "");

ProgressNextStage(_("Updating proxy configuration..."));

/* Update /etc/sysconfig/proxy */
void WriteSysconfig() {
SCR::Write(.sysconfig.proxy.PROXY_ENABLED, enabled?"yes":"no");
SCR::Write(.sysconfig.proxy.HTTP_PROXY, http);
SCR::Write(.sysconfig.proxy.HTTPS_PROXY, https);
SCR::Write(.sysconfig.proxy.FTP_PROXY, ftp);
SCR::Write(.sysconfig.proxy.NO_PROXY, no);
SCR::Write(.sysconfig.proxy, nil);
}

void WriteCurlrc() {
// proxy is used, write /root/.curlrc
// bugzilla #305163
if (enabled) {
Expand Down Expand Up @@ -169,6 +146,37 @@ global define boolean Write() {
}

SCR::Write(.root.curlrc, nil);
}

/**
* Write routing settings and apply changes
* @return true if success
*/
global define boolean Write() {

y2milestone("Writing configuration");
if(!modified) {
y2milestone("No changes to proxy configuration -> nothing to write");
return true;
}

list <string> steps = [
_("Update proxy configuration"),
];

string caption = _("Saving Proxy Configuration");
// sleep for longer time, so that progress does not disappear right afterwards
// but only when Progress is visible
integer sl = (Progress::status() == true ? 500 : 0);

Progress::New(caption, " ", size(steps), steps, [], "");

ProgressNextStage(_("Updating proxy configuration..."));

/* Update /etc/sysconfig/proxy */
WriteSysconfig();

WriteCurlrc();
sleep(sl);
Progress::NextStage();

Expand Down
Empty file added testsuite/tests/ProxyWrite.err
Empty file.
75 changes: 75 additions & 0 deletions testsuite/tests/ProxyWrite.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Read .target.tmpdir "/tmp"
Dump Write: disabled
Write .sysconfig.proxy.PROXY_ENABLED "no" true
Write .sysconfig.proxy.HTTP_PROXY "" true
Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" nil true
Write .root.curlrc nil true
Return true
Dump Write: enabled
Write .sysconfig.proxy.PROXY_ENABLED "yes" true
Write .sysconfig.proxy.HTTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" "proxy.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc nil true
Return true
Dump Write: authenticated
Write .sysconfig.proxy.PROXY_ENABLED "yes" true
Write .sysconfig.proxy.HTTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "User\\\\Domain:P" true
Write .root.curlrc."--proxy" "proxy.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc nil true
Return true
Dump Write: ftp
Write .sysconfig.proxy.PROXY_ENABLED "yes" true
Write .sysconfig.proxy.HTTP_PROXY "" true
Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" nil true
Write .root.curlrc nil true
Return true
Dump Write: authenticated ftp
Write .sysconfig.proxy.PROXY_ENABLED "yes" true
Write .sysconfig.proxy.HTTP_PROXY "" true
Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "U:P" true
Write .root.curlrc."--proxy" nil true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc nil true
Return true
Dump Write: full
Write .sysconfig.proxy.PROXY_ENABLED "yes" true
Write .sysconfig.proxy.HTTP_PROXY "proxy1.example.org:3128" true
Write .sysconfig.proxy.HTTPS_PROXY "proxy2.example.org:3128" true
Write .sysconfig.proxy.FTP_PROXY "proxy3.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "example.org,example.com,localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "U:P" true
Write .root.curlrc."--proxy" "proxy1.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc nil true
Return true
73 changes: 73 additions & 0 deletions testsuite/tests/ProxyWrite.ycp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
include "testsuite.ycp";

map READ = $[
"target" : $[
"tmpdir" : "/tmp",
],
];

map EXEC = $[
"target": $[
"bash_output": $[
"stdout": "2015-01-31\n"
]
]
];

list<map> stubs = [READ, $[], EXEC];
TESTSUITE_INIT(stubs, nil);

import "Proxy";
import "Progress";
Progress::off();

DUMP("Write: disabled");
Proxy::Import($["enabled": false]);
TEST(``(Proxy::Write()), stubs, nil);

DUMP("Write: enabled");
Proxy::Import($[
"enabled": true,
"http_proxy": "proxy.example.org:3128",
]);
TEST(``(Proxy::Write()), stubs, nil);

DUMP("Write: authenticated");
Proxy::Import($[
"enabled": true,
"http_proxy": "proxy.example.org:3128",
"proxy_user": "User\\Domain",
"proxy_password": "P",
]);
TEST(``(Proxy::Write()), stubs, nil);

DUMP("Write: ftp");
Proxy::Import($[
"enabled": true,
"ftp_proxy": "proxy.example.org:3128",
]);
TEST(``(Proxy::Write()), stubs, nil);

DUMP("Write: authenticated ftp");
Proxy::Import($[
"enabled": true,
"ftp_proxy": "proxy.example.org:3128",
"proxy_user": "U",
"proxy_password": "P",
]);
TEST(``(Proxy::Write()), stubs, nil);

DUMP("Write: full");
Proxy::Import($[
"enabled": true,
"http_proxy": "proxy1.example.org:3128",
"https_proxy": "proxy2.example.org:3128",
"ftp_proxy": "proxy3.example.org:3128",
"no_proxy": "example.org,example.com,localhost",
"proxy_user": "U",
"proxy_password": "P",
]);
TEST(``(Proxy::Write()), stubs, nil);

}

0 comments on commit 60be5b2

Please sign in to comment.