Exemple #1
0
 @Test
 public void testFind() throws Exception {
   User foundUser = h2User.find(user.getId());
   assertEquals(email, foundUser.getEmail());
   assertEquals(password, foundUser.getPassword());
   assertEquals(type, foundUser.getType());
 }
Exemple #2
0
 @Test
 public void testUpdate() throws Exception {
   user.setEmail("*****@*****.**");
   user.setPassword("changedPassword");
   user.setType(UserType.STUDENT);
   assertTrue(h2User.update(user));
 }
Exemple #3
0
  @Test
  public void
      testAuthenticateValidAuthInHeaderAndUserInDataStoreButNotAuthorizedToRunAsAnotherUser()
          throws Exception {
    UserObjectifyDAOImpl userDAO = new UserObjectifyDAOImpl();

    User dbuser = new User();
    dbuser.setLogin("bob");
    dbuser.setToken("smith");
    dbuser.setPermissions(Permission.LIST_ALL_JOBS);
    dbuser = userDAO.insert(dbuser);

    AuthenticatorImpl auth = new AuthenticatorImpl();
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteAddr()).thenReturn("192.168.1.1");
    when(request.getHeader(AuthenticatorImpl.AUTHORIZATION_HEADER))
        .thenReturn("Basic " + encodeString("bob:smith"));
    when(request.getParameter(Constants.USER_LOGIN_TO_RUN_AS_PARAM)).thenReturn("joe");

    try {
      auth.authenticate(request);
    } catch (Exception ex) {
      assertTrue(ex.getMessage().equals("User does not have permission to run as another user"));
    }
  }
Exemple #4
0
  // test valid User, but invalid ip
  @Test
  public void testAuthenticateValidAuthButInvalidIp() throws Exception {
    UserObjectifyDAOImpl userDAO = new UserObjectifyDAOImpl();

    User dbuser = new User();
    dbuser.setLogin("bob");
    dbuser.setToken("smith");
    dbuser.setPermissions(Permission.LIST_ALL_JOBS);
    ArrayList<String> allowedIps = new ArrayList<String>();
    allowedIps.add("192.168.1.2");
    dbuser.setAllowedIpAddresses(allowedIps);
    dbuser = userDAO.insert(dbuser);

    AuthenticatorImpl auth = new AuthenticatorImpl();
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteAddr()).thenReturn("192.168.1.1");
    when(request.getHeader(AuthenticatorImpl.AUTHORIZATION_HEADER))
        .thenReturn("Basic " + encodeString("bob:smith"));

    User u = auth.authenticate(request);
    assertTrue(u.getLogin() == null);
    assertTrue(u.getToken() == null);
    assertTrue(u.getPermissions() == Permission.NONE);
    assertTrue(u.getIpAddress().equals("192.168.1.1"));

    verify(request).getHeader(AuthenticatorImpl.AUTHORIZATION_HEADER);
  }
Exemple #5
0
    @Test public void privateView() throws Exception {
        j.createFreeStyleProject("project1");
        User user = User.get("me", true); // create user

        WebClient wc = j.createWebClient();
        HtmlPage userPage = wc.goTo("user/me");
        HtmlAnchor privateViewsLink = userPage.getFirstAnchorByText("My Views");
        assertNotNull("My Views link not available", privateViewsLink);

        HtmlPage privateViewsPage = (HtmlPage) privateViewsLink.click();

        Text viewLabel = (Text) privateViewsPage.getFirstByXPath("//div[@class='tabBar']//div[@class='tab active']/a/text()");
        assertTrue("'All' view should be selected", viewLabel.getTextContent().contains(Hudson_ViewName()));

        View listView = listView("listView");

        HtmlPage newViewPage = wc.goTo("user/me/my-views/newView");
        HtmlForm form = newViewPage.getFormByName("createItem");
        form.getInputByName("name").setValueAttribute("proxy-view");
        ((HtmlRadioButtonInput) form.getInputByValue("hudson.model.ProxyView")).setChecked(true);
        HtmlPage proxyViewConfigurePage = j.submit(form);
        View proxyView = user.getProperty(MyViewsProperty.class).getView("proxy-view");
        assertNotNull(proxyView);
        form = proxyViewConfigurePage.getFormByName("viewConfig");
        form.getSelectByName("proxiedViewName").setSelectedAttribute("listView", true);
        j.submit(form);

        assertTrue(proxyView instanceof ProxyView);
        assertEquals(((ProxyView) proxyView).getProxiedViewName(), "listView");
        assertEquals(((ProxyView) proxyView).getProxiedView(), listView);
    }
 @Before
 public void beforeClass() {
   ci = new CommentInventory();
   c = new Comment();
   u = new User();
   u.setUsername("test");
   u.setEmail("test");
 }
Exemple #7
0
 @Test
 public void testReadFrom() {
   final User user = target("user").request().accept("application/json").get(User.class);
   assertNotNull(user);
   assertNotNull(user.getCreatedOn());
   assertEquals(user.getId().longValue(), 12345L);
   assertEquals(user.getName(), "smallnest");
 }
Exemple #8
0
 @Test
 public void List_Deep_Keys() {
   User u = where(user.firstName.eq("Jaakko")).singleResult(user.addresses.any().street);
   for (Address a : u.getAddresses()) {
     assertNotNull(a.street);
     assertNull(a.city);
   }
 }
  @Test
  public void testLoginUser() throws Exception {
    User user = createUser();
    api.createUser(user);

    String token = api.loginUser(user.getUsername(), user.getPassword());
    assertTrue(token.startsWith("logged in user session:"));
  }
  @Test
  public void deleting_and_add_of_same_mail_address_works() {
    createFullUser(IRRELEVANT);
    createUpdateUserWhereTheSameEmailIsSetToDeleteAndAdd();
    updateUser();

    assertThat(testUser.getEmails(), is(databaseUser.getEmails()));
  }
Exemple #11
0
 @GET
 public User getUser() {
   User user = new User();
   user.setId(12345L);
   user.setName("smallnest");
   user.setCreatedOn(new Date());
   return user;
 }
  @Test
  public void UserNameTest() {
    User u = new User();

    u.setName("foo");

    assertEquals("foo", u.getName());
  }
Exemple #13
0
 @Test
 public void testCostruttoreTot() {
   initTot();
   assertTrue("Username non è quello atteso", user.getUsername() == "Liquid90");
   assertTrue("Nome non è quello atteso", user.getName() == "Giacomo");
   assertTrue("Cognome non è quello atteso", user.getSurname() == "Bain");
   assertTrue("IP non è quello atteso", user.getIP() == "0.0.10.10");
 }
Exemple #14
0
 @Test
 public void testMessages() {
   initTot();
   initMore();
   user.setMessages(rms);
   assertTrue("Il messaggio non è stato inserito", user.isUserMessage(rm));
   user.removeMessage(rm);
   assertFalse("Il messaggio non è stato eliminato", user.isUserMessage(rm));
 }
Exemple #15
0
 @Test
 public void testMessage() {
   initTot(); // inizializzo user
   initOne(); // inizializzo messaggio
   user.setMessage(rm);
   assertTrue("Il messaggio non è stato inserito", user.isUserMessage(rm));
   initOne();
   assertFalse("Il messaggio non dovrebbe essere dell'utente", user.isUserMessage(rm));
 }
  @Test
  public void username_is_set_no_empty_string_is_thrown_probably() {
    createFullUser("ietiuuitp");
    createUpdateUserWithEmptyUserName();

    updateUser();

    assertThat(returnUser.getUserName(), is(equalTo(testUser.getUserName())));
  }
Exemple #17
0
 @Test
 public void List_Keys() {
   User u =
       where(user.firstName.eq("Jaakko")).list(user.firstName, user.mainAddress().street).get(0);
   assertEquals("Jaakko", u.getFirstName());
   assertNull(u.getLastName());
   assertEquals("Aakatu", u.getMainAddress().street);
   assertNull(u.getMainAddress().postCode);
 }
Exemple #18
0
 @Test
 public void References() {
   for (User u : users) {
     if (u.getFriend() != null) {
       assertQuery(user.friend().eq(u.getFriend()), u);
       where(user.friend().ne(u.getFriend())).list();
     }
   }
 }
  @Test
  public void testCreateUser() throws Exception {
    User user = createUser();

    api.createUser(user);

    User fetched = api.getUserByName(user.getUsername());
    assertEquals(user.getId(), fetched.getId());
  }
Exemple #20
0
 @Test
 public void shouldGetEventsOverMultipleDays() {
   Date startDate = firstUser.parseStringToDate("22.09.11 17:00");
   Date endDate = firstUser.parseStringToDate("26.09.11 18:00");
   Event event = new Event("event", startDate, endDate, true);
   firstCalendar.addEvent(event);
   Date testDay = secondUser.parseStringToDate("24.09.11 13:30");
   eventsVisibleToSecondUser = secondUser.getVisibleEventsOnSpecificDayFrom(firstUser, testDay);
   assertTrue(eventsVisibleToSecondUser.contains(event));
 }
  @Test
  public void verifyLogIn_should_return_a_user_with_id_0_if_login_failed() {
    dbHandler.populateUserResult(null);
    initProvider();
    User loginUser = new User(123, "Derp", null, null, null, "123");
    String json = jsonHandler.userToJSON(loginUser);
    User user = provider.verifyLogIn(json);

    assertEquals(0, user.getUserID());
  }
Exemple #22
0
 @Test
 public void shouldNotGetPrivateEvent() {
   Date startDate = firstUser.parseStringToDate("23.09.11 18:00");
   Date endDate = firstUser.parseStringToDate("30.09.11 17:00");
   Event event = new Event("event", startDate, endDate, false);
   firstCalendar.addEvent(event);
   Date testDay = secondUser.parseStringToDate("24.09.11 13:30");
   eventsVisibleToSecondUser = secondUser.getVisibleEventsOnSpecificDayFrom(firstUser, testDay);
   assertFalse(eventsVisibleToSecondUser.contains(event));
 }
Exemple #23
0
  @Test
  public void testSocialNetwork() {
    assertNotNull(reader1);
    SocialNetwork network1 = reader1.getSocialNetwork();
    assertNotNull(network1);

    assertNotNull(network1.getNodes());
    long nodes = 0;
    if (network1.getNodes() instanceof Collection<?>) {
      nodes = ((Collection<?>) network1.getNodes()).size();
    } else {
      for (User node : network1.getNodes()) {
        nodes++;
      }
    }
    assertEquals(network1.getSize(), nodes);
    assertEquals(network1.getSize(), 107092);

    User user1 = network1.getNodeById(1);
    assertNotNull(user1);
    assertTrue(user1.isHomeLocationKnown());

    User user3 = network1.getNodeById(3);
    assertNotNull(user3);
    assertFalse(user3.isHomeLocationKnown());

    assertEquals(user1.getFriends().size(), 4); // friendships are undirected!!

    assertFalse(user1.getFriends().contains(user1));

    User user43344 = network1.getNodeById(43344);
    assertTrue(user1.getFriends().contains(user43344)); // 1 and 43344 are friends!!
    assertTrue(user43344.getFriends().contains(user1));
  }
  @Test
  public void shouldReturnUsersPhone() {
    User user = new User();
    user.addPhone("123 456 789");

    List<String> phones = user.getPhones();

    assertNotNull(phones);
    assertFalse(phones.isEmpty());
    assertEquals(1, phones.size());
    assertTrue(phones.contains("123 456 789"));
  }
  @Test
  public void testGetSetWithCast() {
    CouchbaseCache cache = new CouchbaseCache(cacheName, client);

    String key = "couchbase-cache-user";
    User user = new User();
    user.firstname = "Michael";

    cache.put(key, user);

    User loaded = cache.get(key, User.class);
    assertNotNull(loaded);
    assertEquals(user.firstname, loaded.firstname);
  }
  @Test
  public void
      verifyLogIn_should_return_a_user_with_matching_password_and_username_but_password_should_be_null() {
    User loginUser = new User(42, "User1", null, null, null, "123");
    ArrayList<User> expected = new ArrayList<User>();
    expected.add(loginUser);
    dbHandler.populateUserResult(expected);
    initProvider();
    String json = jsonHandler.userToJSON(loginUser);
    User user = provider.verifyLogIn(json);

    assertEquals("User1", user.getUsername());
    assertNull(user.getPassword());
  }
Exemple #27
0
  // test Authenticate invalid decode of authString no colon
  @Test
  public void testAuthenticateInvalidAuthNoColon() throws Exception {
    AuthenticatorImpl auth = new AuthenticatorImpl();
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteAddr()).thenReturn("192.168.1.1");
    when(request.getHeader(AuthenticatorImpl.AUTHORIZATION_HEADER))
        .thenReturn("Basic " + encodeString("ha"));
    User u = auth.authenticate(request);
    assertTrue(u != null);
    assertTrue(u.getPermissions() == Permission.NONE);
    assertTrue(u.getIpAddress().equals("192.168.1.1"));

    verify(request).getHeader(AuthenticatorImpl.AUTHORIZATION_HEADER);
  }
  @Test
  public void testFindUser() throws Exception {

    // Stub the value that will returned on call to userService.findUserByName
    User stubbedUser = new User("userAfterSave");
    Mockito.when(userService.findUserByName("user1")).thenReturn(stubbedUser);

    // make the call
    User user = userManager.findUser("user1");

    // Verify if findUserByName method was invoked on userService call
    Mockito.verify(userService).findUserByName("user1");

    Assert.assertEquals("userAfterSave", user.getUserName());
  }
Exemple #29
0
 @Issue("JENKINS-9367")
 @Test public void allImagesCanBeLoaded() throws Exception {
     User.get("user", true);
     WebClient webClient = j.createWebClient();
     webClient.setJavaScriptEnabled(false);
     j.assertAllImageLoadSuccessfully(webClient.goTo("asynchPeople"));
 }
 @Issue("JENKINS-18641")
 @Test
 public void display() throws Exception {
   User.get("bob");
   JenkinsRule.WebClient wc = j.createWebClient();
   HtmlPage page;
   try {
     page = wc.goTo("asynchPeople");
   } catch (FailingHttpStatusCodeException x) {
     System.err.println(x.getResponse().getResponseHeaders());
     System.err.println(x.getResponse().getContentAsString());
     throw x;
   }
   assertEquals(0, wc.waitForBackgroundJavaScript(120000));
   boolean found = false;
   for (DomElement table : page.getElementsByTagName("table")) {
     if (table.getAttribute("class").contains("progress-bar")) {
       found = true;
       assertEquals("display: none;", table.getAttribute("style"));
       break;
     }
   }
   assertTrue(found);
   /* TODO this still fails occasionally, for reasons TBD (I think because User.getAll sometimes is empty):
   assertNotNull(page.getElementById("person-bob"));
   */
 }