File apache2-mod_authnz_external-3_2.spec of Package apache2-mod_authnz_external

#
# spec file for package apache2-mod_authnz_external-3_2
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define mod_name mod_authnz_external
#
Name:           apache2-mod_authnz_external
Version:        3.2.6
Release:        0
#
Summary:        Apache External Authentication Modules
License:        Apache-2.0
#
Group:          Productivity/Networking/Web/Servers
#
Url:            http://code.google.com/p/mod-auth-external/
Source:         http://mod-auth-external.googlecode.com/files/%{mod_name}-%{version}.tar.gz
BuildRequires:  apache2-devel
BuildRequires:  apache-rpm-macros
BuildRequires:  curl
Requires:       %{apache_mmn}
Requires:       %{apache_suse_maintenance_mmn}
# imho pwauth is not strictly needed?
#Requires:       pwauth
#
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
The Apache HTTP Daemon can be configured to require users to supply logins and
passwords before accessing pages in some directories. Authentication is the
process of checking if the password given is correct for a user. Apache has
standard modules for authenticating out of several different kinds of
databases. These external authentication modules provide a flexible tool for
creating authentication systems based on other databases.

%prep
%setup -q -n %{mod_name}-%{version}
rm -rf .libs/ .*.swp

%build
%{apache_apxs} -c %{mod_name}.c

%install
install -Dd -m 0755 %{buildroot}%{apache_libexecdir}
%{apache_apxs} -S LIBEXECDIR="%{buildroot}%{apache_libexecdir}" -i -n %{mod_name} %{mod_name}.la

%check
set +x
mkdir -p %{apache_test_module_dir}/htdocs/protected
# create test document
cat << EOF >  %{apache_test_module_dir}/htdocs/protected/index.html
RESTRICTED AREA
EOF
# create external authenticifation provider
cat << EOF > %{apache_test_module_dir}/dummy-auth
#!/bin/bash
read user
read passwd
if [ "\$user" == "\$passwd" ]; then
  exit 0
else
  exit 1
fi
EOF
chmod +x %{apache_test_module_dir}/dummy-auth
# create module conf
cat << EOF > %{apache_test_module_dir}/%{mod_name}-test.conf
DefineExternalAuth dummy_auth pipe %{apache_test_module_dir}/dummy-auth
<Directory %{apache_test_module_dir}/htdocs/protected>
  AuthType Basic
  AuthName "Restricted Area"
  AuthBasicProvider external
  AuthExternal dummy_auth
  Require valid-user
</Directory>
EOF
# run test apache instance
exit_code=0
%apache_test_module_start_apache -m authn_default:authz_user:authnz_external -i %{mod_name}-test.conf
echo
echo 'Test /protected/ output'
# this must to be authenticated
%apache_test_module_curl -u wilma:wilma -d /protected/ -o output.txt
grep 'RESTRICTED AREA' output.txt || exit_code=1
# this must not to be authenticated
%apache_test_module_curl -u wilma:betty -d /protected/ -o output.txt
grep '<title>.*401.*</title>' output.txt || exit_code=1
echo -n 'Result: '
if [ $exit_code -eq 0 ]; then
  echo 'SUCCESS'
else
  echo "FAILED, error_log:"
  cat %{apache_test_module_dir}/error_log
fi
echo
# stop test apache instance
%apache_test_module_stop_apache
set -x
exit $exit_code

%files
%defattr(-,root,root,-)
%{apache_libexecdir}/%{mod_name}.so
%doc mysql/ test/
%doc AUTHENTICATORS CHANGES INSTALL* README TODO UPGRADE