Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests for auth. plugins #232

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Functional tests for auth. plugins #232

wants to merge 5 commits into from

Conversation

celestian
Copy link
Contributor

There is a basic set of functional tests for auth. plugins.

For this set it is essential to use parameters, so we don't use fixtures but context manager which prepare right configuration and start Custodia server for us.

For more testing is good idea to prepare class which can prepare more difficult configuration automatically.

This is preparation extension of functional tests.

Signed-off-by: Petr Čech <pcech@redhat.com>
@codecov-io
Copy link

codecov-io commented Aug 18, 2017

Codecov Report

Merging #232 into master will increase coverage by 0.65%.
The diff coverage is 87.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #232      +/-   ##
=========================================
+ Coverage   72.74%   73.4%   +0.65%     
=========================================
  Files          41      42       +1     
  Lines        4433    4614     +181     
  Branches      449     484      +35     
=========================================
+ Hits         3225    3387     +162     
- Misses       1052    1057       +5     
- Partials      156     170      +14
Impacted Files Coverage Δ
tests/functional/base.py 86.69% <84.9%> (+0.33%) ⬆️
tests/functional/test_plugin_auth.py 96.07% <96.07%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a76747b...b6d26ca. Read the comment docs.

Petr Čech added 4 commits August 22, 2017 10:04
This test suite tries entire configuration matrix of SimpleCredsAuth
plugin.

Signed-off-by: Petr Čech <pcech@redhat.com>
This test suite tests configuration options of SimpleHeaderAuth
plugin.

Signed-off-by: Petr Čech <pcech@redhat.com>
Signed-off-by: Petr Čech <pcech@redhat.com>
Signed-off-by: Petr Čech <pcech@redhat.com>
@celestian
Copy link
Contributor Author

I just removed invalid comments from configuration templates.

@@ -17,8 +20,105 @@
from custodia.server.config import parse_config


def wait_pid(process, wait):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move the functions out of the class? If the test class doesn't suite your needs, please talk to @raildo and modify the base class.

current_uid = None

if meta_uid == "correct_id":
current_uid = pwd.getpwuid(os.geteuid()).pw_uid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda pointless, SOCK_PEERCRED always returns the effective uid and gid.

current_gid = None

if meta_gid == "correct_id":
current_gid = grp.getgrgid(os.getegid()).gr_gid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito, os.getegid() is enough.

raise OSError('Timeout error')


def translate_meta_uid(meta_uid):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead using translate_meta_uid(), I'd rather see some constants, e.g.:

USER_ID, USER_NAME, USER_WRONG_ID, USER_WRONG_NAME = get_test_user()

class UniqueNumber(object):
unique_number = 0

def get_unique_number(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is not necessary. If you add request to any test argument list, then you can access the test name as request.node.name. The name also contains the parameter values. This gives you an unique name that reflects the test case, too.

self.custodia_conf = os.path.join(self.test_dir, 'custodia.conf')
self.params = conf_params

self.out_fd = os.open(os.devnull, os.O_RDWR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaks a fd when enter fails. My original code used a global scoped fixture to have a single FD for all tests.

self.env = os.environ.copy()
self.env['CUSTODIA_SOCKET'] = self.config['server_socket']

def _get_conf_template(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this approach. You should rather create specialized subclasses in each test module:

class SimpleCredsCustodiaServer(CustodiaServer):
    template = 'tests/functional/conf/template_simple_creds_auth.conf'

    def extra_parameters(self):
        return {
            'UID': translate_meta_uid(self.params['meta_uid']),
            'GID': translate_meta_gid(self.params['meta_gid'])
         }

'meta_uid': meta_uid,
'meta_gid': meta_gid}

with CustodiaServer(self.test_dir, params) as server:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will start and stop a server for each parameter, which is rather slow. Do we really need integration tests for this case? You can archive the same test coverage with a unit test.

Copy link
Contributor Author

@celestian celestian Aug 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the speed is not our issue as long as you could run tests without those. But the point is that I look on Custodia as on black box. I really would like to test it in this way, because it is really essential use case. I want to see that entire Custodia work properly in this point.

If this is unacceptable to you, I can limit the set considerably. But I really don't prefer it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants