~ubuntu-branches/ubuntu/saucy/syslog-ng/saucy

« back to all changes in this revision

Viewing changes to modules/afmongodb/libmongo-client/tests/unit/mongo/sync/sync_cmd_authenticate.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2011-11-15 08:48:02 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111115084802-n0jegdnjlxk0m26s
Tags: 3.3.1.dfsg-1ubuntu1
* debian/control: remove libsystemd-daemon-dev build-depends
* debian/rules: remove --with-systemdsystemunitdir from
  override_dh_auto_configure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "test.h"
 
2
#include "mongo.h"
 
3
#include "config.h"
 
4
 
 
5
#include <errno.h>
 
6
#include <sys/socket.h>
 
7
#include "libmongo-private.h"
 
8
 
 
9
void
 
10
test_mongo_sync_cmd_authenticate_net_secondary (void)
 
11
{
 
12
  mongo_sync_connection *c;
 
13
 
 
14
  skip (!config.secondary_host, 4,
 
15
        "Secondary server not configured");
 
16
 
 
17
  c = mongo_sync_connect (config.secondary_host, config.secondary_port, TRUE);
 
18
  mongo_sync_conn_set_auto_reconnect (c, TRUE);
 
19
  mongo_sync_cmd_is_master (c);
 
20
 
 
21
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "s3kr1+") == TRUE,
 
22
      "mongo_sync_cmd_authenticate() works");
 
23
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "bad_pw") == FALSE,
 
24
      "mongo_sync_cmd_authenticate() should fail with a bad password");
 
25
  ok (mongo_sync_cmd_authenticate (c, config.db, "xxx", "s3kr1+") == FALSE,
 
26
      "mongo_sync_cmd_authenticate() should fail with a bad username");
 
27
 
 
28
  shutdown (c->super.fd, SHUT_RDWR);
 
29
  sleep (3);
 
30
 
 
31
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "s3kr1+") == TRUE,
 
32
      "mongo_sync_cmd_authenticate() automatically reconnects");
 
33
 
 
34
  mongo_sync_disconnect (c);
 
35
 
 
36
  endskip;
 
37
}
 
38
 
 
39
void
 
40
test_mongo_sync_cmd_authenticate_net (void)
 
41
{
 
42
  mongo_sync_connection *c;
 
43
 
 
44
  begin_network_tests (8);
 
45
 
 
46
  c = mongo_sync_connect (config.primary_host, config.primary_port, TRUE);
 
47
  mongo_sync_conn_set_auto_reconnect (c, TRUE);
 
48
 
 
49
  mongo_sync_cmd_user_add (c, config.db, "test", "s3kr1+");
 
50
 
 
51
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "s3kr1+") == TRUE,
 
52
      "mongo_sync_cmd_authenticate() works");
 
53
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "bad_pw") == FALSE,
 
54
      "mongo_sync_cmd_authenticate() should fail with a bad password");
 
55
  ok (mongo_sync_cmd_authenticate (c, config.db, "xxx", "s3kr1+") == FALSE,
 
56
      "mongo_sync_cmd_authenticate() should fail with a bad username");
 
57
 
 
58
  shutdown (c->super.fd, SHUT_RDWR);
 
59
  sleep (3);
 
60
 
 
61
  ok (mongo_sync_cmd_authenticate (c, config.db, "test", "s3kr1+") == TRUE,
 
62
      "mongo_sync_cmd_authenticate() automatically reconnects");
 
63
 
 
64
  mongo_sync_disconnect (c);
 
65
 
 
66
  test_mongo_sync_cmd_authenticate_net_secondary ();
 
67
 
 
68
  end_network_tests ();
 
69
}
 
70
 
 
71
void
 
72
test_mongo_sync_cmd_authenticate (void)
 
73
{
 
74
  mongo_sync_connection *c;
 
75
 
 
76
  c = test_make_fake_sync_conn (-1, FALSE);
 
77
 
 
78
  errno = 0;
 
79
  ok (mongo_sync_cmd_authenticate (NULL, "test", "test",
 
80
                                        "s3kr1+") == FALSE,
 
81
      "mongo_sync_cmd_authenticate() fails with a NULL connection");
 
82
  cmp_ok (errno, "==", ENOTCONN,
 
83
          "errno is set to ENOTCONN");
 
84
 
 
85
  errno = 0;
 
86
  ok (mongo_sync_cmd_authenticate (c, NULL, "test", "s3kr1+") == FALSE,
 
87
      "mongo_sync_cmd_authenticate() fails with a NULL db");
 
88
  cmp_ok (errno, "==", EINVAL,
 
89
          "errno is set to EINVAL");
 
90
 
 
91
  errno = 0;
 
92
  ok (mongo_sync_cmd_authenticate (c, "test", NULL, "s3kr1+") == FALSE,
 
93
      "mongo_sync_cmd_authenticate() fails with a NULL user");
 
94
  cmp_ok (errno, "==", EINVAL,
 
95
          "errno is set to EINVAL");
 
96
 
 
97
  errno = 0;
 
98
  ok (mongo_sync_cmd_authenticate (c, "test", "test", NULL) == FALSE,
 
99
      "mongo_sync_cmd_authenticate() fails with a NULL password");
 
100
  cmp_ok (errno, "==", EINVAL,
 
101
          "errno is set to EINVAL");
 
102
 
 
103
  ok (mongo_sync_cmd_authenticate (c, "test", "test",
 
104
                                        "s3kr1+") == FALSE,
 
105
      "mongo_sync_cmd_authenticate() fails with a bogus FD");
 
106
 
 
107
  mongo_sync_disconnect (c);
 
108
 
 
109
  test_mongo_sync_cmd_authenticate_net ();
 
110
}
 
111
 
 
112
RUN_TEST (17, mongo_sync_cmd_authenticate);