Exemplo n.º 1
0
  /**
   * ע��
   *
   * @param account ע���ʺ�
   * @param password ע������
   * @return 1��ע��ɹ� 0��������û�з��ؽ��2������˺��Ѿ�����3��ע��ʧ��
   */
  public String regist(String account, String password) {
    if (getConnection() == null) return "0";
    AccountManager am = AccountManager.getInstance(getConnection());
    am.sensitiveOperationOverInsecureConnection(true);
    try {
      am.createAccount(account, password);
      return "1";
    } catch (NoResponseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (XMPPErrorException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NotConnectedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return "3";

    //        Registration reg = new Registration();
    //        reg.setType(IQ.Type.set);
    //        reg.setTo(getConnection().getServiceName());
    //        // ע������createAccountע��ʱ��������UserName������jid����"@"ǰ��IJ��֡�
    //        reg.setUsername(account);
    //        reg.setPassword(password);
    //        // ���addAttribute����Ϊ�գ�������?����������־��android�ֻ��İɣ���������
    //        reg.addAttribute("android", "geolo_createUser_android");
    //        PacketFilter filter = new AndFilter(new PacketIDFilter(
    //                reg.getPacketID()), new PacketTypeFilter(IQ.class));
    //        PacketCollector collector = getConnection().createPacketCollector(
    //                filter);
    //        getConnection().sendPacket(reg);
    //        IQ result = (IQ) collector.nextResult(SmackConfiguration
    //                .getDefaultPacketReplyTimeout());
    //        // Stop queuing resultsֹͣ����results���Ƿ�ɹ��Ľ��
    //        collector.cancel();
    //        if (result == null) {
    //            Log.e("regist", "No response from server.");
    //            return "0";
    //        } else if (result.getType() == IQ.Type.RESULT) {
    //            Log.v("regist", "regist success.");
    //            return "1";
    //        } else { // if (result.getType() == IQ.Type.ERROR)
    //            if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
    //                Log.e("regist", "IQ.Type.ERROR: "
    //                        + result.getError().toString());
    //                return "2";
    //            } else {
    //                Log.e("regist", "IQ.Type.ERROR: "
    //                        + result.getError().toString());
    //                return "3";
    //            }
    //        }
  }
  /**
   * If the initiator can connect to a SOCKS5 proxy but activating the stream fails an exception
   * should be thrown.
   *
   * @throws Exception should not happen
   */
  @Test
  public void shouldFailIfActivateSocks5ProxyFails() throws Exception {

    // build error response as reply to the stream activation
    XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
    IQ error =
        new IQ() {

          public String getChildElementXML() {
            return null;
          }
        };
    error.setType(Type.ERROR);
    error.setFrom(proxyJID);
    error.setTo(initiatorJID);
    error.setError(xmppError);

    protocol.addResponse(
        error, Verification.correspondingSenderReceiver, Verification.requestTypeSET);

    // start a local SOCKS5 proxy
    Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
    socks5Proxy.start();

    StreamHost streamHost = new StreamHost(proxyJID, socks5Proxy.getAddress());
    streamHost.setPort(socks5Proxy.getPort());

    // create digest to get the socket opened by target
    String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

    Socks5ClientForInitiator socks5Client =
        new Socks5ClientForInitiator(streamHost, digest, connection, sessionID, targetJID);

    try {

      socks5Client.getSocket(10000);

      fail("exception should be thrown");
    } catch (XMPPErrorException e) {
      assertTrue(XMPPError.Condition.internal_server_error.equals(e.getXMPPError().getCondition()));
      protocol.verifyAll();
    }

    socks5Proxy.stop();
  }
Exemplo n.º 3
0
  @Test
  public void getConfigFormWithInsufficientPriviliges()
      throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);

    Node node = mgr.getNode("princely_musings");

    PubSub errorIq = new PubSub();
    XMPPError error = new XMPPError(Condition.forbidden);
    errorIq.setError(error);
    con.addIQReply(errorIq);

    try {
      node.getNodeConfiguration();
    } catch (XMPPErrorException e) {
      Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
    }
  }